Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

send form data with file upload using ajax

// HTML
<form id="upload_form" enctype="multipart/form-data"></form>

// or specify exact data for FormData()
var formData = new FormData($('#upload_form')[0]);
formData.append('section', 'general');
formData.append('action', 'previewImg');
// Attach file
formData.append('image', $('input[type=file]')[0].files[0]); 
//Sending form


//Ajax request with jquery will looks like this:
$.ajax({
    url: 'Your url here',
    data: formData,
    type: 'POST',
    contentType: false, // NEEDED, DON'T OMIT THIS (requires jQuery 1.6+)
    processData: false, // NEEDED, DON'T OMIT THIS
    // ... Other options like success and etc
});
 
PREVIOUS NEXT
Tagged: #send #form #data #file #upload #ajax
ADD COMMENT
Topic
Name
6+3 =