i have form on site thats submitted true ajax. form has field attache .pdf files. how when submitting form though file not send rest of data.
how can work? here ajax code:
$('#submit_btn').click(function () { $.ajax({ type: 'post', url: '/contact.php', datatype: "json", data: $('#contactform').serialize(), success: function (data) { console.log(data.type); console.log(data.msg); var nclass = data.type; var ntxt = data.msg; $("#notice").attr('class', 'alert alert-' + nclass).text(ntxt).remove('hidden'); //reset fields if success if (nclass != 'danger') { $('#contactform input').val(''); $('#contactform textarea').val(''); } } }); return false; }); on php side have phpmailer setup , handling file so:
if(!empty($_files['file'])) { $_m->addattachment($_files['file']['tmp_name'],$_files['file']['name']); }
$('#submit_btn').click(function () { var formdata = new formdata($('#contactform')); $.ajax({ type: 'post', url: '/contact.php', // datatype: "json", data: formdata , processdata: false, contenttype: false, success: function (data) { console.log(data.type); console.log(data.msg); var nclass = data.type; var ntxt = data.msg; $("#notice").attr('class', 'alert alert-' + nclass).text(ntxt).remove('hidden'); //reset fields if success if (nclass != 'danger') { $('#contactform input').val(''); $('#contactform textarea').val(''); } } }); return false; });
Comments
Post a Comment