Answer the question
In order to leave comments, you need to log in
The image is not loaded by Ajax - where is the error?
Uploading an image (Codeigniter)
<input class="myinput" name="userfile" type="file" />
$('.myinput').change(function(){
var fd = new FormData();
$.ajax({
url: "/index.php/images/upload",
type: "POST",
data: fd,
processData: false,
contentType: false,
success: function(data){
alert(data);
}
});
});
print_r( $_FILES )
but returns an empty array. In the console I see that there are no errors. The image is also not loading anywhere. What's my mistake?
Answer the question
In order to leave comments, you need to log in
The error is that you are passing empty data. Try wrapping it in a form:
<form>
<input class="myinput" name="userfile" type="file" />
</form>
var fd = new FormData($("form")[0]); // <- Передать данные с формы
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question