Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Since maybe you can start many AJAX requests, I'd argue that one of best solutions - basically, a reliable solution - is first creating an array of requests' state like this:
- var ajaxRequestsState = [];
- //When you start an AJAX request, you should add an element to this array like this one:
- ajaxRequestsState.push({ requestId: "some identifier" });
- //Later, if you need to check if there's no active request, you can have a flag like so:
- function isAsyncRequestActive() {
- return ajaxRequestsState.length > 0;
- }
- //Finally, whenever a request ends or fails, you must do so:
- function releaseRequest(requestId) {
- var requestIndex = 0;
- var found = false;
- while(!found && requestIndex < ajaxRequestsState.length)
- {
- found = ajaxRequestsState[requestIndex].requestId == requestId;
- requestIndex++;
- }
- if(found) {
- ajaxRequestsState.splice((requestIndex-1), 1);
- }
- }
- releaseRequest("identifier of request which ended or failed");
- //That's simply tracking requests' state and maintaining a collection of requests' states, and you'll have it!
Add Comment
Please, Sign In to add comment