I'm having a problem with a JavaScript function and a variable.
I'm use AJAX to get values from the server and I've a JavaScript external file that use a variable that is returned by AJAX. The problem is that variable is appears undefined when I try to use this variable inside the external file. The result of the AJAX call is a HTML page that includes this variable used by the external JavaScript file, but when the answer arrives the variable appears in the DOM and if I try to used this variable inside the external JavaScript file I'm getting an error "is not defined".
Example: AJAX CALL
function fillModal(url) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if ((this.readyState === 4) && (this.status === 200)) {
document.getElementById("dataModal").innerHTML = this.responseText;
}
};
xhttp.open("GET", url, true);
xhttp.send();
}
Variable used in the external JavaScript file returned by the AJAX reponse
function isOneRowTable(table_name) {
OneRowTable // This is the name of the variable returned by the AJAX call.
}