I am trying to set a boolean value inside StatusCode of an ajax call which I could re-use later for some other work. This is what I tried:
window.flag = false; // This is the flag I am trying to set inside Status Code 200
$(document).ready(function() {
$("#btnSubmit").click(function(){
jQuery.ajax({
'url': 'http://localhost:8080//Test/abc/',
dataType : 'jsonp',
crossDomain:true,
async:false,
statusCode: {
200: function() {
alert('Success'); // This popup is displayed
flag = true; // Here I am trying to set the flag to TRUE
alert(flag); // Here I am getting TRUE in alert
}
}
});
// But here the flag value is coming as FALSE; I am expecting TRUE value
if(flag == false){
alert('Failure');
}
});
});
The alert pop-up is displaying 'Success' inside the StatusCode callback, the value of flag is set to true and the alert for flag is displaying TRUE.
BUT when I try using it inside the if condition check, the value is coming as False.
Please let me know how to retrieve the correct value for the flag.