#437 bug
mirko

Ajax.Request (on FF) fires onSuccess when server is down

Reported by mirko | November 10th, 2008 @ 08:27 PM | in After 1.7

hi all.

try this: - play with a local server (apache?) - create a simple page with an element attached (onclick) with the function below - click the element and all goes well: both FireFox and IE fires the onSuccess event with the alert "onSuccess (status: 200)" and then the onComplete event - stop the server (put it offline) - click the element again: now IE fires the onFailure event and then the on Complete (that is, i think, correct), FireFox still fires the onSuccess event (status: 0 !) and then the onComplete event


eventOnClick = function() {
	new Ajax.Request(this.location.href, {
		method: "post",
		onSuccess: function(transport) {
			alert("onSuccess (status: " + transport.status + ")");
			if (transport.status == 0) {
				try {
					// try to fire correct event
				//	transport.request.options.onFailure(transport);
				} catch (e) {}
				return;
			}
			// do something useful...
		},
		onFailure: function(transport) {
			alert("onFailure");
			// something went wrong
		},
		onComplete: function(transport) { alert("onComplete"); }
	});
}

in my opinion this is a bug of FF (version 3.0.3 on win) implementation of XMLHttpRequest, not a Prototype issue, but my solution for this is to check the transport status (200 = ok) before call the onSuccess callback. try to uncomment the row into the try-catch and now FF goes right like IE. but i love FF! :-) i discovered this issue writing a long-polling ajax component for php playing with timeouts and simulating connection problems.

thanks for your work

mirko.it

Comments and changes to this ticket

  • Tobie Langel

    Tobie Langel November 11th, 2008 @ 12:42 AM

    • Milestone set to 1.7
    • State changed from “new” to “bug”
    • Tag changed from ajax.request, connection, explorer, firefox, firefox3, needs_tests, onfailure, onsuccess, server to ajax.request, needs_patch, needs_tests
    • Assigned user set to “Tobie Langel”
  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 02:26 AM

    • Tag changed from ajax.request, needs_patch, needs_tests to missing:tests, needs_patch

    [not-tagged:"needs_tests" tagged:"missing:tests" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 02:28 AM

    • Tag changed from missing:tests, needs_patch to missing:patch, missing:tests

    [not-tagged:"needs_patch" tagged:"missing:patch" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 03:36 AM

    • Tag changed from missing:patch, missing:tests to missing:patch, needs:tests

    [not-tagged:"missing:tests" tagged:"needs:tests" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 03:37 AM

    • Tag changed from missing:patch, needs:tests to needs:patch, needs:tests

    [not-tagged:"missing:patch" tagged:"needs:patch" bulk edit command]

  • T.J. Crowder

    T.J. Crowder November 16th, 2009 @ 04:50 PM

    • Assigned user cleared.

    [responsible:none bulk edit command]

  • Tobie Langel

    Tobie Langel March 1st, 2010 @ 12:39 AM

    • Tag changed from needs:patch, needs:tests to needs:patch, needs:tests, section:ajax
  • Sergiu Dumitriu

    Sergiu Dumitriu March 15th, 2010 @ 03:38 AM

    Automatically assuming that a response status of 0 is a failure is not a good solution, since Opera transforms a (successful) 204 status code into 0. These are incompatible browser bugs, and there's little that can be done in a custom javascript.

  • Taloncor

    Taloncor May 14th, 2010 @ 04:01 PM

    Calling transport.abort() on any Ajax.Request will also trigger onSuccess with status 0 in Firefox (FF. 3.6.3 in this case)

            var request = new Ajax.Request("long_running.cgi", {
                onSuccess: function(response){
                        alert("onSuccess. Status:"+response.status);
                    },
                onFailure: function(response){
                        alert("onFailure. Status:"+response.status);
                    },
                });
            request.transport.abort();
    
  • Andrew Dupont

    Andrew Dupont October 17th, 2010 @ 08:23 AM

    • Milestone changed from 1.7 to After 1.7
    • Importance changed from “” to “”

    I have no idea what to do about this one, as it's much like Sergiu said. Moving this to the next milestone in the hope that someone will discover a miraculous heuristic that can tell successful zeros from unsuccessful zeros.

  • Nathan Trevivian

    Nathan Trevivian June 18th, 2012 @ 06:02 PM

    Raised #1358 which seems to be a duplicate of this. Is there anyway of wrapping transport so that abort must always be called on the Ajax.Request object? Then you could track whether the code aborted it, or whether the target was not communicating. Is that bad form? Could then associate with an onAborted handler function...

  • Nathan Trevivian

    Nathan Trevivian June 19th, 2012 @ 12:48 PM

    The XHR could, of course, be aborted if it hasn't finished and the page is reloaded, so there would also have to be a document unloaded listener to check for these types of abortions as well.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

The Prototype JavaScript library.

Shared Ticket Bins

Referenced by

Pages