Browser aborting Ajax requests sporadically without returning any errors

<>

This question already has an answer here:

Answers


Could fit your needs, sending request one by one should avoid server rejecting some parallel requests:

TEST IT

$(document).ready(function () {
    var tot = 30; //to simulate 30 requests
    (function request(i){
        if(i === tot) return;
        $.get('/echo/html/?'+i, function (data) {
            console.log("success");
        }).always(function() { request(++i) });
    })(0);
});

You can serialize requests with a global object:

function AjaxRequester() {
    this.queue = [];
}

AjaxRequester.prototype.doRequest(request){
    if (this.queue.length>0){
        this.queue.push(request)
    }
    else 
       handleRequest(request)
}

AjaxRequester.prototype.handleRequest(request){
    /* actually handle ajax request, on complete inspect 
       queue and if not empty recall this method on the first
       element */
}

requester = new AjaxRequester();

into your code, do

requester.doRequest(yourRequest);

I think your server is taking too long to respond and the browser is timing out. It may be that the browser will only have two open connections to the server and is aborting the last 8/10 when the first two take too long. I would check your server logs to confirm this.

What is the server doing when it sees a request to /i18n/javaScript/pt.json? Four seconds is a long time. Try fetching some static content like an image or some static HTML instead of pt.json and see if that fixes the problem.

If you need to do a lot of computation to produce pt.json, can it be cached? Is it very large? Are you using Apache?


If this is a cache issue then you may try this:

Add the following markup in your page's header. That will prevent the browser from caching any data.

<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1990 12:00:00 GMT" />

This will disable caching in most of the browsers, and your data will be fetched on each refresh as there is no cache,

One more thing. Your data is called in loop... I can say it is a continuous call with same request, so the request might be considered as a duplicate request and may get cancelled by the service; As that might be considered as a flood of requests if the same request is sent again and again...

Try adding something while calling, like this..

for (var i = 0; i < 10; i++) {
    $.get('/i18n/javaScript/pt.json?v='+i, function(data) {
        console.log(data);
    });
}

And handle the request with something. Try and see if it works..

If calling open() using, as you are using, jQuery, it's built in, and it will have an effect.

Refer an Stack Overflow Old Post How to solve Firebug’s “Aborted” messages upon Ajax requests?.

I am sure this will give you positive lead towards solution...


Need Your Help

Convert to sql query

c# sql

Explanation: I have a list of client objects that contains datetime lasthello and string isconnect amongst others.

Zend Framework, run query without a view?

php database zend-framework model controller

I am currently building a small admin section for a website using Zend Framework, this is only my second time of using the framework so I am a little unsure on something things. for example are I h...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.