I am using AJAX to save some data. I need to save FormData and other info. I am using the below function, but I am not sure how to add the other information to the FormData object. Could you please help?
function vignetteAjax(company_id, client_id, type_id, url) {
var formData = document.getElementById("edit_form");
var fd = new FormData(myform);
$.ajax({
url: url,
type: "post",
data: {
"_token": "{{ csrf_token() }}",
"company_id": company_id,
"client_id": client_id,
"type_id": type_id,
},
beforeSend: function() {},
success: function(data) {
console.log('done');
$("#policies_list").empty().html(data);
},
complete: function() {
console.log('compete');
}
});
return 0;
}
3
Answers
You can send the entire Form-Data via Post
Also, hence you are using jQuery, you dont need to use document.getElementById(“edit_form”). You can directly use $(‘#edit_form’).
On the PHP Side (assuming you use PHP), use parse_str to unserialize.
you just need to append the other data with your
FormData
Use the
append
method to add the additional data to theFormData
object, then send just theFormData
object.