I\'m trying to serialize my form data including file image field using jquery.form.js jQuery API. The API is helping me to serailze data fields including image
HTML
Javascript (note that any methods following self are instance methods, I use Joose)
$(form).ajaxSubmit({//note that form is just the form built with a jQuery selector
url: self.returnBaseULR() + '/ajaxadd',
type: 'POST',
error: function(xhr, status, error) {
console.log('Unable to contact the server');
},
success: function(response){
var jsObjectFromResponse = JSON.parse(response);
if(jsObjectFromResponse.success){
self.cLog('Item uploaded successfully!');
document.location.reload();
} else {
self.cLog('Listing failed, see AJAX response');
}
}
});
You can't upload images using just jQuery native methods. Check out http://jquery.malsup.com/form/
It has methods that'd do this for you perfectly.
That just appears to work for me. On the back end I can grab POST params with $_POST and files with $_FILES (or something like that)
Looks like ajaxSubmit instantly posts the form with serialized data done automatically.
Hope that helps.