This question has already been answered:

How to submit a file with a form? Everything except the file is transferred ... Thanks in advance a lot !!!

<form id="InsetForm" action="javascript:void(null);" onsubmit="call() method="post" enctype="multipart/form-data"> <input id="FirstName" name="FirstName" value="" type="text"> <input id="LastName" name="LastName" value="" type="text"> <input id="ImageFile" name="ImageFile" accept=".jpg" type="file"> <input value="Send" type="submit"> </form> <script type="text/javascript" language="javascript"> function call() { var msg = $('#InsetForm').serialize(); $.ajax({ type: 'POST', url: 'Insert.php', data: msg, success: function(data) {alert(data);}, error: function(xhr, str){ alert('Возникла ошибка'); } }); } </script> 

Reported as a duplicate by participants Alexey Shimansky , aleksandr barakin , user194374, sercxjo , Streletz Jul 5 '16 at 18:52 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

1 answer 1

See an example with FormData JSFIDDLE

More about FormData

 function setimage() { var $input = $("#uploadimage"); var fd = new FormData; fd.append('img', $input.prop('files')[0]); $.ajax({ url: 'http://example.com/script.php', data: fd, processData: false, contentType: false, type: 'POST', success: function (data) { alert(data); } }); } 
  • Why write an answer if it is clearly a duplicate, which should be closed ....... um ..... as a duplicate? - Alexey Shimansky