Reputation: 117
I have this kind of form: method="post" enctype="multipart/form-data"
Everytime the form is submitted via ajax
$("#openTicketSubmit").click(function(){
var support_ticket_form_data = new FormData($("#support_ticket_form"));
$.ajax({
type: "POST",
url: "{$systemurl}submit_ticket.php",
data: support_ticket_form_data,
contentType: 'multipart/form-data',
success: function(results){
console.log(results);
},
error( xhr, ajaxOptions, thrownError ){
console.log( thrownError );
}
});
});
It got an error: jquery.min.js:4 Uncaught TypeError: Illegal invocation and then in the server side (php) the $_POST is null.
Please somebody help me.
Upvotes: 0
Views: 287
Reputation: 97672
To do a multipart/form-data request with jQuery.ajax, contentType
and processData
needs to be set to false.
Also the FormData constructor takes a form object not a jquery one
var support_ticket_form_data = new FormData($("#support_ticket_form")[0]);
Upvotes: 1