Closed Bug 486511 Opened 15 years ago Closed 14 years ago

Wrong ajax callback response when reloading or going to another page

Categories

(Firefox :: General, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED INCOMPLETE

People

(Reporter: carlosorden, Unassigned)

Details

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

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:1.9.0.8) 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".





<html>
<head>
<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);
        req.send(null);
    // 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);
            req.send();
        }
    }
}

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

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

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


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.
Status: UNCONFIRMED → RESOLVED
Closed: 14 years ago
Resolution: --- → INCOMPLETE
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>
<html>
  <body>
    <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'); };
      
      xhr.send();
    </script>
  </body>
</html>

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.