I use this code to upload file with ajax.
$('form').submit(function(e) {
e.preventDefault();
var fd = new FormData(this);
$.ajax({url: $(this).attr('action'),
xhr: function() { // custom xhr (is the best)
var xhr = new XMLHttpRequest();
//load
xhr.upload.addEventListener("load", function(evt) {
$("#msg").text(evt.target.responseText);
}, false);
return xhr;
},
type: 'post',
processData: false,
contentType: false,
data: fd,
success: function(data) {
// do something...
}});
});
I want to display a message in the #msg div when the upload is complete. The message is printed server side using php. Normally evt.target.responseText contains the data from the server, but it contains [object XMLHttpRequestProgressEvent] (which in turn gets written to #msg). I tried printing evt.responseText and evt.response but both also return [object XMLHttpRequestProgressEvent].
Return data from webserver with javainstead ofReturn data from webserver with ajaxbecause I am dumb. Can anyone fix this real quick?