jQuery: The Write Less, Do More JavaScript Library

ajaxComplete doesn't fire on 404 (should it?)

View: New views
4 Messages — Rating Filter:   Alert me  

ajaxComplete doesn't fire on 404 (should it?)

by Mr Speaker :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I searched around for this, but couldn't find any mention of it...
which seems a bit spooky, but I'll post it anyway. In this code:
$("#complete").ajaxComplete( function(){ $(this).text("complete"); });

$("#start")
        .ajaxStart(function(){$(this).text("start")})
        .ajaxStop(function(){$(this).text("Stop")});

$.ajax({ type:"get", url:"iDontExist.php" });

If the request 404's, then neither the ajaxComplete or ajaxStop events
fire. In the jQuery ajax code (line 455 in 1.4pre) it says:
// Send the data
try {
        xhr.send( type === "POST" || type === "PUT" ? s.data : null );
} catch(e) {
        jQuery.handleError(s, xhr, null, e);
}

But nothing is done to call the complete() method. If I whack a call
to complete() in the catch block then everyone looks happy (perhaps...
I don't know if you can get the status of the request as 404?).

Anyhoo... my question is - is this expected behaviour? That is, does
"ajaxComplete" not fire because technically the request didn't
complete or something?

Thanks!

Earle.

--

You received this message because you are subscribed to the Google Groups "jQuery Development" group.
To post to this group, send email to jquery-dev@....
To unsubscribe from this group, send email to jquery-dev+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en.



Re: ajaxComplete doesn't fire on 404 (should it?)

by John Resig :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hmm, that does sound like a bug. Could you file a ticket and mention
the tweak that you made? Thanks!

--John



On Fri, Nov 6, 2009 at 7:16 AM, Mr Speaker <mrspeaker@...> wrote:

> I searched around for this, but couldn't find any mention of it...
> which seems a bit spooky, but I'll post it anyway. In this code:
> $("#complete").ajaxComplete( function(){ $(this).text("complete"); });
>
> $("#start")
>        .ajaxStart(function(){$(this).text("start")})
>        .ajaxStop(function(){$(this).text("Stop")});
>
> $.ajax({ type:"get", url:"iDontExist.php" });
>
> If the request 404's, then neither the ajaxComplete or ajaxStop events
> fire. In the jQuery ajax code (line 455 in 1.4pre) it says:
> // Send the data
> try {
>        xhr.send( type === "POST" || type === "PUT" ? s.data : null );
> } catch(e) {
>        jQuery.handleError(s, xhr, null, e);
> }
>
> But nothing is done to call the complete() method. If I whack a call
> to complete() in the catch block then everyone looks happy (perhaps...
> I don't know if you can get the status of the request as 404?).
>
> Anyhoo... my question is - is this expected behaviour? That is, does
> "ajaxComplete" not fire because technically the request didn't
> complete or something?
>
> Thanks!
>
> Earle.
>
> --
>
> You received this message because you are subscribed to the Google Groups "jQuery Development" group.
> To post to this group, send email to jquery-dev@....
> To unsubscribe from this group, send email to jquery-dev+unsubscribe@....
> For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en.
>
>
>

--

You received this message because you are subscribed to the Google Groups "jQuery Development" group.
To post to this group, send email to jquery-dev@....
To unsubscribe from this group, send email to jquery-dev+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en.



Re: ajaxComplete doesn't fire on 404 (should it?)

by Mr Speaker :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

After some more testing I realised it was not so serious - it only
occurred when 404ing from the local filesystem. This doesn't actually
generate a 404, but an NS_ERROR_DOM_BAD_URI error which gets caught in
the try/catch. Still - anything that falls through to the catch block
will not call complete() so ajaxStop and ajaxComplete don't get fired,
and the jQuery.active count doesn't get decremented.

I've filled a ticket and diff (http://dev.jquery.com/ticket/5468)

Earle.

On Nov 7, 1:05 am, John Resig <jere...@...> wrote:

> Hmm, that does sound like a bug. Could you file a ticket and mention
> the tweak that you made? Thanks!
>
> --John
>
> On Fri, Nov 6, 2009 at 7:16 AM, Mr Speaker <mrspea...@...> wrote:
> > I searched around for this, but couldn't find any mention of it...
> > which seems a bit spooky, but I'll post it anyway. In this code:
> > $("#complete").ajaxComplete( function(){ $(this).text("complete"); });
>
> > $("#start")
> >        .ajaxStart(function(){$(this).text("start")})
> >        .ajaxStop(function(){$(this).text("Stop")});
>
> > $.ajax({ type:"get", url:"iDontExist.php" });
>
> > If the request 404's, then neither the ajaxComplete or ajaxStop events
> > fire. In the jQuery ajax code (line 455 in 1.4pre) it says:
> > // Send the data
> > try {
> >        xhr.send( type === "POST" || type === "PUT" ? s.data : null );
> > } catch(e) {
> >        jQuery.handleError(s, xhr, null, e);
> > }
>
> > But nothing is done to call the complete() method. If I whack a call
> > to complete() in the catch block then everyone looks happy (perhaps...
> > I don't know if you can get the status of the request as 404?).
>
> > Anyhoo... my question is - is this expected behaviour? That is, does
> > "ajaxComplete" not fire because technically the request didn't
> > complete or something?
>
> > Thanks!
>
> > Earle.
>
> > --
>
> > You received this message because you are subscribed to the Google Groups "jQuery Development" group.
> > To post to this group, send email to jquery-dev@....
> > To unsubscribe from this group, send email to jquery-dev+unsubscribe@....
> > For more options, visit this group athttp://groups.google.com/group/jquery-dev?hl=en.
>
>

--

You received this message because you are subscribed to the Google Groups "jQuery Development" group.
To post to this group, send email to jquery-dev@....
To unsubscribe from this group, send email to jquery-dev+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en.



Re: Re: ajaxComplete doesn't fire on 404 (should it?)

by John Resig :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ah, great - thanks for the clarification and patch!

--John



On Sat, Nov 7, 2009 at 7:26 AM, Mr Speaker <mrspeaker@...> wrote:

> After some more testing I realised it was not so serious - it only
> occurred when 404ing from the local filesystem. This doesn't actually
> generate a 404, but an NS_ERROR_DOM_BAD_URI error which gets caught in
> the try/catch. Still - anything that falls through to the catch block
> will not call complete() so ajaxStop and ajaxComplete don't get fired,
> and the jQuery.active count doesn't get decremented.
>
> I've filled a ticket and diff (http://dev.jquery.com/ticket/5468)
>
> Earle.
>
> On Nov 7, 1:05 am, John Resig <jere...@...> wrote:
>> Hmm, that does sound like a bug. Could you file a ticket and mention
>> the tweak that you made? Thanks!
>>
>> --John
>>
>> On Fri, Nov 6, 2009 at 7:16 AM, Mr Speaker <mrspea...@...> wrote:
>> > I searched around for this, but couldn't find any mention of it...
>> > which seems a bit spooky, but I'll post it anyway. In this code:
>> > $("#complete").ajaxComplete( function(){ $(this).text("complete"); });
>>
>> > $("#start")
>> >        .ajaxStart(function(){$(this).text("start")})
>> >        .ajaxStop(function(){$(this).text("Stop")});
>>
>> > $.ajax({ type:"get", url:"iDontExist.php" });
>>
>> > If the request 404's, then neither the ajaxComplete or ajaxStop events
>> > fire. In the jQuery ajax code (line 455 in 1.4pre) it says:
>> > // Send the data
>> > try {
>> >        xhr.send( type === "POST" || type === "PUT" ? s.data : null );
>> > } catch(e) {
>> >        jQuery.handleError(s, xhr, null, e);
>> > }
>>
>> > But nothing is done to call the complete() method. If I whack a call
>> > to complete() in the catch block then everyone looks happy (perhaps...
>> > I don't know if you can get the status of the request as 404?).
>>
>> > Anyhoo... my question is - is this expected behaviour? That is, does
>> > "ajaxComplete" not fire because technically the request didn't
>> > complete or something?
>>
>> > Thanks!
>>
>> > Earle.
>>
>> > --
>>
>> > You received this message because you are subscribed to the Google Groups "jQuery Development" group.
>> > To post to this group, send email to jquery-dev@....
>> > To unsubscribe from this group, send email to jquery-dev+unsubscribe@....
>> > For more options, visit this group athttp://groups.google.com/group/jquery-dev?hl=en.
>>
>>
>
> --
>
> You received this message because you are subscribed to the Google Groups "jQuery Development" group.
> To post to this group, send email to jquery-dev@....
> To unsubscribe from this group, send email to jquery-dev+unsubscribe@....
> For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en.
>
>
>

--

You received this message because you are subscribed to the Google Groups "jQuery Development" group.
To post to this group, send email to jquery-dev@....
To unsubscribe from this group, send email to jquery-dev+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en.