Reputation: 138
How to put FormData object into a form and submit it by using ajaxForm plugin? I'm trying to do something as below:
var fd = new FormData();
fd.append('photo', file);
var form = $("<form method='POST' action='url.php' enctype='multipart/form-data'></form>");
add the fd formData as the object to the form and convert the form into ajaxForm by:
form.ajaxForm({
beforeSend: function(e) {},
uploadProgress: function(event, position, total, percentComplete) {},
complete: function(data) {}
});
then submit the form. So in the url.php I can fetch the file by $_FILES['photo'];
Upvotes: 1
Views: 24105
Reputation: 53
That's what is working for me
var fd = new FormData(this);
fd.append('upload', file);
$(this).ajaxSubmit({
formData: fd,
...
});
Upvotes: 0
Reputation: 223
You can directly send data as like normal ajax post..
Like ..
form.ajaxForm({
data: { data: fd },
beforeSubmit:function() {
}
beforeSend: function(e) {},
uploadProgress: function(event, position, total, percentComplete) {},
complete: function(data) {}
});
I have tested it and it is working fine..
Upvotes: 2