I am using Springer OpenAccess API with JS, they provide their data with many ways, one of them is jsonp format. My code is shown below. What ever i do, i couldn’t make it run synchronuously. Callback mechanism is good solution but i want to learn how to run this function syncronously or how enable this function to behave syncronous.
Any help will be appreciated.
SpringerAPI.prototype.getArticleInfo = function(doi){
//create url of article according to given doi...
var url = this.endpoint.host+this.endpoint.method+''+'?q=doi:'+doi+'&api_key='+this.endpoint.apikey+"&callback=?";
//get information about article...
//perform async request to the Springer API
this.situation = true;
var article;
jQuery.ajax({
method:'POST',
url: url,
dataType: 'JSON',
cache: true,
async: false, // to set local variable
success: function(data)
{
article = FromSpringerToArticle(data,-1);
}
});
return article;
};
You can’t do synchronous JSONP because jQuery doc says
You’ll have to do an asyc operation and use callbacks.