This is an answer to the question asked by the original author in the comments of his question
Can you provide an example of such AJAX call please?
Without jQuery (Plain JavaScript)
function getData(url, callback) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
callback(this.responseText);
}
};
xhttp.open("GET", url, true);
xhttp.send();
}
function useData(data) {
// This is where you are going to use the data to display your page (tables, text, etc...)
// /!\ `data` is still a string. If you're using JSON for example, don't forget to `JSON.parse()` before using the code.
console.log(data);
}
// and finally call the getData function with the url and the callback
getData("myData.php", useData);
Using jQuery:
function getData(url, callback) {
$.ajax({
url: url,
method: "GET",
success: callback,
error: function(xhr, textStatus, errorThrown) {
alert("AJAX error: " + errorThrown);
}
});
}
function useData(data) {
// This is where you are going to use the data to display your page (tables, text, etc...)
// This time, jQuery will do an intelligent guess and automatically parse your data. So wether you're using XML, JSON, ..., it's going to get parsed.
console.log(data);
}
// and finally call the getData function with the url and the callback
getData("myData.php", useData);