Following is my ajax call in which I am sending my form data to a PHP page and diplaying the messages accordingly. The issue I am facing is with ajax seralize() post my file is not getting posted and send.php gives error in response Notice: Undefined index: file
. Kindly let me know what is an appropriate way to post form data with ajax enctype="multipart/form-data"
so files can be send as a post too via ajax.
var post_data = $( "#form" ).serialize();
$.ajax({
type: "POST",
url: "send.php",
async: false,
data: post_data,
success: function(html){
if (html.indexOf("filerror") != -1)
{
alert('error');
}
else if(html.indexOf("true") != -1)
{
alert('true');
}
else if (html.indexOf("false") != -1)
{
alert('false');
}
},
beforeSend:function()
{
}
});