Bug Tracker

Modify

Ticket #4086 (closed bug: fixed)

Opened 4 years ago

Last modified 4 years ago

$().load() & $.ajaxSetup bug

Reported by: mk Owned by:
Priority: minor Milestone: 1.3.2
Component: ajax Version: 1.3.1
Keywords: Cc:
Blocking: Blocked by:

Description

In my main .js file i have this line (I use it to show loading image at beginning of ajax request and hide it when it finishes).

$.ajaxSetup({dataType:'json', beforeSend:function() { loading.show(); }, complete:function() { loading.hide(); }})

It works fine with $.post(), $.get()... but when using $().load() it will only show loading, it won't hide it. I tried to put alert() instead of loading functions, only one alert is shown.

Attachments

jQueryLoadTestCase.rar Download (1.4 KB) - added by mk 4 years ago.
Test example

Change History

comment:1 Changed 4 years ago by dmethvin

Can you provide a test case?

Changed 4 years ago by mk

Test example

comment:2 Changed 4 years ago by mk

Yes, here you can test it online:  http://www.mma-studio.com/jQueryLoadTestCase/

I've also attached this as rar archive.

comment:3 Changed 4 years ago by zitiger

I find this problem today, can someone verify it?

comment:4 Changed 4 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to fixed

The jQuery.load method calls jQuery.ajax with its own complete handler, which overrides the one that would have come in through jQuery.ajaxSettings. However, if you were to have used the success handler then load would work and the others would fail.

Instead of using jQuery.ajaxSettings to set handlers, you should be using the ajax global events such as ajaxComplete. I've edited the docs to make this a bit clearer.

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.