Wrong ajax callback response when reloading or going to another page




9 years ago
a year ago


(Reporter: Tschar, Unassigned)


Firefox Tracking Flags

(Not tracked)


(Whiteboard: [CLOSEME 2010-11-01])



9 years ago
User-Agent:       Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/2009032609 Firefox/3.0.8 (.NET CLR 3.5.30729)

If you have Ajax requests in queue and you reload the page or go to another page, the "onreadystatechange" function is still being reached with "status=0" (other browsers seem to drop these requests once you moved to a new page (let's say, a page that hasn't requested anything yet)

Reproducible: Always

Steps to Reproduce:
In the following example:

1. Click several time on "request file by Ajax" to cause that some requests are queued.

2. Immediatly afterward reload the page or click on "Go to another site".

<title>Ajax test</title>
<script language="javascript">

var req;

function loadXMLDoc(url) 
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);

function processReqChange() 
    // only if req shows "complete"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
        } else {
            alert("Problems retrieving data.\n[Status: " + req.status + "]");

function requestFile(x)
	loadXMLDoc("bigfile.txt?rnd=" + Math.random());

function callback_requestFile()
	// Do something
<a href="javascript: requestFile()">Request file by AJAX</a>
<a href="javascript: window.location.href='http://www.mozilla.com'">Go to another site!!</a>

Actual Results:  
You'll se the message box with the error.

Expected Results:  
Drop ajax requests generated by other pages than the current page

There are many site which use ajax and if you click on reload while a request is pending you get an error. For example, the (new) yahoo webmail among others.
This is a mass search for bugs which are in the Firefox General component, are
UNCO, have not been changed for 500 days and have an unspecified version. 

Reporter, can you please update to Firefox 3.6.10 or later, create a fresh profile, http://support.mozilla.com/en-US/kb/managing+profiles, and test again. If you still see the issue, please update this bug. If the issue is gone, please set the status to RESOLVED > WORKSFORME.
Whiteboard: [CLOSEME 2010-11-01]
No reply from reporter, INCOMPLETE. Please retest with Firefox 3.6.12 or later and a new profile (http://support.mozilla.com/kb/Managing+profiles). If you continue to see this issue with the newest firefox and a new profile, then please comment on this bug.
Last Resolved: 7 years ago
Resolution: --- → INCOMPLETE

Comment 3

a year ago
This issue still exists in the latest version of Firefox (49.0.1) with a new profile.

According to our understanding of the HTML spec, when navigating across documents (https://html.spec.whatwg.org/multipage/browsers.html#navigating-across-documents) the browser should abort the active document (https://html.spec.whatwg.org/multipage/browsers.html#abort-a-document). Aborting a document includes the following:
"Cancel any instances of the fetch algorithm in the context of this Document, DISCARDING ANY TASKS QUEUED FOR THEM, and discarding any further data received from the network for them." - apologies for the capitals for emphasis

Bug replication steps:
1) Paste the following HTML into a file and serve it from a web server.
<!doctype html>
    <script type="text/javascript">
      var xhr = new XMLHttpRequest();
      xhr.open('GET', 'https://fake-response.appspot.com/api/?sleep=5', true);

      xhr.onabort = function onAbort() { console.log('abort'); };
      xhr.onerror = function onError() { console.log('error'); };
      xhr.onload = function onLoad() { console.log('loaded'); };

2) Navigate to the page and open the developer tools.

3) Refresh before 5 seconds have elapsed and you will see that "error" is logged to the console.

Nothing should be logged to the console as the tasks associated with any fetch algorithms should be discarded
You need to log in before you can comment on or make changes to this bug.