0

I am sending form data via an ajax request using jQuery's $.ajax..

It sends some input fields, etc. I also have a file upload button that I need to have function with the jQuery.

How can I do this simultaneously while sending the POST data from the form?

I have found questions answered that explain how to do an AJAX file upload but ONLY that. I need to do the AJAX file upload WHILE submitting POST data from a form filled out...

$('#gobutton').click(function(e) {
    e.preventDefault();

    var payment_type = $('.change').val();
    var terms = 0;

    if($('#terms').is(':checked'))
        terms = 1;

    $.ajax({
        url: 'code2.php',
        type: 'POST',
        data: { gobutton: 'Update', 
                terms: terms,
                file: file
         },
         success: function(result) {
            $('#feedback').html(result);
         }
    });
});
user3817533
  • 639
  • 3
  • 11
  • 17
  • Is the file a mandatory part of the form, or is an optional attachment? – ffflabs Jul 11 '14 at 18:20
  • There is a fairly new HTML5 protocol named FormData that you can use to accomplish this but it is not supported by a number of older browsers. – ssergei Jul 11 '14 at 18:21
  • I voted to reopen, but after I was [outvoted 3-1](http://stackoverflow.com/review/reopen/5278991) I took a second look, and it seems that the linked question, and at least one of the answers, *do* focus on uploading during a POST. – Adi Inbar Jul 11 '14 at 18:59

0 Answers0