javascript - Ajax form $_POST blank return data -
var name = jquery('[data-field="name"]').val(); var email = jquery('[data-field="email"]').val(); var inumber = jquery('[data-field="inumber"]').val(); var rnumber = jquery('[data-field="rnumber"]').val(); var date = jquery('[data-field="date"]').val(); var amount = jquery('[data-field="amount"]').val(); var feedback = jquery('[data-field="name"]').val(); var file_attach = new formdata(jquery('input[name^="media"]')); jquery.each(jquery('input[name^="media"]')[0].files, function(i, file) { file_attach.append(i, file); }); jquery.ajax({ type: 'post', data: { func: "sendmail", name,email,inumber,rnumber,date,amount,feedback,file_attach}, url: 'billing-information-mailer.php', cache: false, contenttype: false, processdata: false, success: function(data){ console.log(data); } });
i'm trying pass form info , attachment php file send email, went $.post
need set processdata false shifted $.ajax
, php file sending empty return. code in php file print_r($_post);
edit:
<input type="file" name="media" data-field="billing" id="vdnupload" name="vdnupload" placeholder="proof of payment">
the syntax of object you're providing data
property incorrect each item needs key.
however more pressing problem upload file need put data (file , input values) in formdata
object , send alone. try this:
var formdata = new formdata(); $.each($('input[name^="media"]')[0].files, function(i, file) { formdata.append(i, file); }); formdata.append('name', $('[data-field="name"]').val()); formdata.append('email', $('[data-field="email"]').val()); formdata.append('inumber', $('[data-field="rnumber"]').val()); formdata.append('rnumber', $('[data-field="rnumber"]').val()); formdata.append('date', $('[data-field="date"]').val()); formdata.append('amount', $('[data-field="amount"]').val()); formdata.append('feedback', $('[data-field="name"]').val()); $.ajax({ type: 'post', data: formdata, url: 'billing-information-mailer.php', cache: false, contenttype: false, processdata: false, success: function(data){ console.log(data); } });
you make much, simpler if place form
element around inputs want include in request. way can provide reference of form formdata
constructor , values populated you:
var formdata = new formdata($('#myform')[0]);
Comments
Post a Comment