I've been racking my brain for a couple hours now and doing a lot of searching and I cannot seem to find an answer. I want to know if it is possible to return the xmlhttp.responseText value from an AJAX function to the function that originally called the AJAX function.
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
//document.getElementById("err").style.color="red";
my_response = xmlhttp.responseText;
alert(my_response);
return my_response;
}
}
}
I want to return the my_response variable to the original caller. No matter what I try I have been unsuccessful. I even tried assigning it to the global window variable using window.my_response = xmlhttp.responseText but it ends up being undefined.
Every example I've seen of using AJAX pretty much does something inside of the if (xmlhttp.status == 200) part to update the web page. I really do not want to do that.
Can I return the value? Thanks for your help.
By the way, the ajax function works fine because the alert works properly.
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
//document.getElementById("err").style.color="red";
console.log(row);
row.child( format(row.data())).show();
tr.addClass('shown');
}
}
The code of format function is above this.