My experience with ajax calls, particularly involving API's and JavaScript, is limited. I am currently using the Microsoft Translator API with ajax and calling a callback function in the following manner:
ac.push(tgtId);
s.src = "http://api.microsofttranslator.com/V2/Ajax.svc/Translate" +
"?appId=Bearer " + encodeURIComponent(token) +
"&from=" + encodeURIComponent(src) +
"&to=" + encodeURIComponent(tgt) +
"&text=" + encodeURIComponent(elem.value) +
"&oncomplete=mycallback";
The issue I'm encountering is that I need to either make this call synchronous or pass a parameter in the callback function so that my code can identify which request the response corresponds to.
Currently, I've tried maintaining an array called "ac" where I push the ID sequentially after each request and then retrieve it in the callback method using the following code:
function mycallback(response)
{
id(ac[0]).value=response;
ac.shift();
}
However, this approach doesn't work as the ajax call is asynchronous.
Any assistance would be greatly appreciated.