Starting from the code provided by filedrag.js I've implemented an upload file async function.
The problem is that I can't retrieve the text once the call is done. Actually I'm sure the text is returned, since it shows up in firebug console once the POST request is done. The problem is that my code doesn't add it to the page.
Here's the code:
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
function showHint(str,action,target,url) {
xmlhttp.open("POST",url,true);
xmlhttp.setRequestHeader("enctype","multipart/form-data");
var fd = new FormData;
fd.append('filexls', str);
xmlhttp.send(fd);
console.log(xmlhttp.status);
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
$('#successup').html(xmlhttp.responseText);
}
}
I've done some testing and I think the problem is with the last part of the code. If I place the console.log(xmlhttp.status)
before the if
statement, it returns 0
(firebug at the end of the request returns 200
), while if I place it inside the if
nothing shows up in the console. So my best guess is that the problem is that the if
statement runs before the actual request is done an so it returns false
.