Answer the question
In order to leave comments, you need to log in
FILES ajax empty variable coming, why?
An empty file arrives, although everything worked a couple of days ago:
function prov() {
var data = new FormData($('#prov')[0]);
$.ajax({
type: "POST",
url: "/engine/prov.php",
data: data,
contentType: false,
processData: false,
success: function(response) {
console.log(response)
}
});
}
<form method="post" id="prov" action="" enctype="multipart/form-data">
<div class="input-wrapper">
<input id="provtxt" type="text" name="provtxt">
<label for="img"><i class="fa fa-paperclip" aria-hidden="true"></i></label>
<input id="img" type="file" name="img">
</div>
</form>
<button onclick="prov();" class="send-btn">ОТПРАВИТЬ</button>
Answer the question
In order to leave comments, you need to log in
var $input = $("#prov");
var fd = new FormData;
fd.append('img', $input.prop('files')[0]);
$.ajax({
url: '/engine/prov.php,
data: fd,
processData: false,
contentType: false,
type: 'POST',
success: function (data) {
alert(data);
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question