0

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.

1 Answer 1

1

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]);
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you very much brother! this one solves the problem: $("#support_ticket_form")[0] I have another question, why is that when I echo the $SERVER['REQUEST_METHOD'] it is null? :/
Do you mean $_SERVER['REQUEST_METHOD']?
yeah, I misspelled the $_SERVER into $SERVER. Thank you bro.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.