I have a common generic function which will make use for ajax calls. While triggering the first time I will get the whole data from the server and I will maintain local scope. So In in the second time, it won't the server for the data. In my case the problem is the first request is async request while processing the first request second request is coming and again it is hitting the server. Now, how I can put the second request in waiting for state until the first request was finished?
a.js
will call the call.js
which has the ajax call: get();
b.js
also will call the same function. In the second the data was available in global
variable so that it won't make any ajax call: get();
call.js:
var get = function() {
var global = [];
if (Object.keys(global).length)
retrun global;
ajaxcall({
// ...
}).done(function(data) {
global = data;
}).fail(function(err) {
});
}
In this case while processing the first request second request is coming. So it is making another call.