Bug Tracker

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#8079 closed bug (worksforme)

remote getJSON calls never decrement the jQuery.active property

Reported by: jiles@… Owned by:
Priority: high Milestone: 1.next
Component: ajax Version: 1.4.4
Keywords: Cc:
Blocked by: Blocking:

Description

When making a remote getJSON call the jQuery.active property is incremented, but never returned to 0 once the script is added.

On line 5790 the jsonp value is set:

jsonp = s.jsonpCallback || ("jsonp" + jsc++);

On line 5868 it checks for jsonp being set:

// Handle Script loading
if ( !jsonp ) {

with line 5790 it will always be true, it doesn't enter the if statement, and the success and complete events never fire to decrement the active property.

Change History (4)

comment:1 Changed 8 years ago by jitter

Component: unfiledajax
Priority: undecidedhigh
Resolution: worksforme
Status: newclosed

Thanks for taking the time to contribute to the jQuery project by writing a bug report!

As you didn't provide a test case I quickly made this test case up myself. I can't reproduce what you are describing. Neither with jQuery 1.4.4 or the current 1.5rc1 version.

Actually if I remember correctly there was a bug in earlier versions where the active property was decremented too often for jsonp calls. Also the jQuery.active property isn't documented so you shouldn't rely on it being present or doing what you think it does because it might changed or removed altogether at some point.

comment:2 Changed 8 years ago by jitter

Milestone: 1.next1.4.3

comment:3 Changed 8 years ago by jiles@…

Thanks for taking the time to look at this and providing an example and thorough explanation. After looking at the example it made me explore our issue a little deeper. Turns out ours is failing because the url is actually responding as html, not javascript. (It's a third party script)

I created a variation from your example to show it happening. http://jsfiddle.net/4pjdj/.

You can also see it at http://hiring.snagajob.com where it makes a call to dev.visualwebsiteoptimizer.com/log_hit.php if it's your first time on the site and to dev.visualwebsiteoptimizer.com/log_clickmap.php every time you click the page after that. Both calls cause the active variable to increment, but not decrement.

It's my assumption that the complete event should be called even if the response type is incorrect. I believe that would decrement $.active correctly.

Also, I understand your point about the active property not being a documented feature, however, it's the core of our automated test framework which uses it to ensure the page has fully loaded and is not in the process of making any additional ajax calls before it starts running tests on the page.

Thanks again for your help

comment:4 Changed 8 years ago by jitter

Milestone: 1.4.31.next

For non-crossdomain local jsonp requests, which return the wrong content-type, as in this test case you would be fine with the new 1.5rc1 version, as the error and complete callback are triggered and the active counter is correctly decreased.

For cross-domain jsonp requests (which use script tags as a transport) this unfortunately isn't so easy. There is no easy way to check if loading a script tag has failed or not. Check #3227 and #7763 for more information and maybe progress on this issue.

Note: See TracTickets for help on using tickets.