Defining a Global variable in JavaScript/jQuery and getting it later in script.
But strange it is not working.
printing getResult in console giving me undefined.
but when trying to print getResult just after the assigned value to it, it is giving me accurate value.
Actually i need ajax result at the bottom .. how could i do this..?
var getResult;
$.getJSON(url, function(data) {
//JS statement to Ajax
//JS statement to Ajax
$.ajax({
type: "post",
dataType: "json",
url: urlTo,
data: dataSend,
success: function (result, status) {
getResult = result;
console.log(getResult); // getResult is working here
}
});
//JS statement to Ajax
//JS statement to Ajax
$.ajax({
type: "post",
dataType: "json",
url: urlTo2,
data: dataSend2,
success: function (result2, status) {
}
});
console.log(getResult); // getResult is not working here. Giving " undefined" result here.
});