Bug Tracker

Modify

Ticket #3235 (closed bug)

Opened 5 years ago

Last modified 14 months ago

ajax error event is not being reported in some situations

Reported by: attilam Owned by:
Priority: major Milestone: 1.3
Component: ajax Version: 1.2.6
Keywords: Cc: attilam, flesler, nathanhammond
Blocking: Blocked by:

Description

When you are trying to call a URL that fails due to such errors as NS_ERROR_DOM_BAD_URI, the error function registered with the ajax settings is not being called.

The reason it is not called is because an exception is thrown during the call at either of the following lines:

xhr.open(type, s.url, s.async, s.username, s.password); or xhr.open(type, s.url, s.async);

To resolve this issue, wrap the above calls in a try/catch block and in the catch block call the following:

jQuery.handleError(s, xhr, null, e);

Attachments

3235.html Download (548 bytes) - added by nathanhammond 5 years ago.
Test Case
3235.diff Download (756 bytes) - added by nathanhammond 5 years ago.
Better Patch.

Change History

comment:1 Changed 5 years ago by flesler

  • Cc attilam, flesler added
  • need changed from Review to Test Case

Could you provide a test case ? a minimalistic html file with the requires html and js to reproduce the problem. Thanks.

Changed 5 years ago by nathanhammond

Test Case

Changed 5 years ago by nathanhammond

Better Patch.

comment:2 Changed 5 years ago by nathanhammon

The new patch takes care of the problem and passes all collected information to the error handler as it returns.

comment:3 follow-up: ↓ 5 Changed 5 years ago by flesler

  • Cc nathanhammond added

Does that test case actually cause an exception ? it seems fine to me.

comment:4 Changed 5 years ago by flesler

  • Component changed from core to ajax

comment:5 in reply to: ↑ 3 Changed 5 years ago by nathanhammon

Replying to flesler:

Does that test case actually cause an exception ? it seems fine to me.

It does locally for me. It is trying to request  http://jquery.com when I'm on localhost. I'm updating the patch to add a test.

comment:6 Changed 5 years ago by nathanhammon

I'm having trouble figuring out why adding a test for this one is causing another test to fail to start (pass-through request object). The whole test suite works just fine without adding in the new test, so I'm obviously doing something wrong.

What I'm working off of (appears right after the error callbacks):

test("jQuery.ajax() - xhr.open error callbacks", function() {
    expect( 3 );
    stop();

    jQuery('#foo').ajaxStart(function(){
        start();
        ok( true, "ajaxStart" );
    }).ajaxStop(function(){
        ok( true, "ajaxStop" );
    }).ajaxSend(function(){
        ok( true, "ajaxSend" );
    }).ajaxComplete(function(){
        ok( true, "ajaxComplete" );
    }).ajaxError(function(){
        ok( true, "ajaxError" );
    }).ajaxSuccess(function(){
        ok( false, "ajaxSuccess" );
    });

    jQuery.ajax({
        type: "GET",
        dataType: "html",
        url: url("http://jquery.com"),
        beforeSend: function(){ ok(true, "beforeSend"); },
        success: function(){ ok(false, "success"); },
        error: function(){ ok(true, "error"); },
        complete: function(){ ok(true, "complete"); }
    });
});

comment:7 Changed 3 years ago by snover

  • Status changed from new to pending

This ticket has been marked as missing a test case. In an effort to reduce the number of outstanding tickets in the bug tracker, it will be closed automatically in 30 days. In order to prevent this from happening, please provide a working test case. If a test case has already been provided and our records are wrong, please respond to the ticket so that it can be fixed. Thank you!

comment:8 Changed 3 years ago by trac-o-bot

  • Status changed from pending to closed

Automatically closed due to 14 days of inactivity.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.