Below are the codes I have written:
Function for sending an AJAX request and getting a value in return:
function myAjaxCall(){
var myValue=0;
var async = false; //I need to make a synchronized request, otherwise the return value is 0
xmlhttp.open("GET", URL, async);
xmlhttp.onreadystatechange=function(){
...
myValue = SOMEVALUE;
};
xmlhttp.send();
return myValue;
}
Another function that makes use of the value returned by myAjaxCall function:
function otherFunc(){
var x = myAjaxCall();
}
Everything works perfectly except on Firefox browser. This issue arises because in Firefox, the onreadystatechange
will not be called if synchronized requests are used.
In my scenario, synchronous ajax requests are necessary. If not used, the return value of myAjaxCall()
function will always remain as the initial value "var myValue=0
".
How can I solve this problem specific to Firefox?