Skip to main content

Bug Tracker

Side navigation

#8079 closed bug (worksforme)

Opened January 27, 2011 11:51PM UTC

Closed January 28, 2011 09:34AM UTC

Last modified January 29, 2011 04:46AM UTC

remote getJSON calls never decrement the jQuery.active property

Reported by: jiles@snagajob.com 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.

Attachments (0)
Change History (4)

Changed January 28, 2011 09:34AM UTC by jitter comment:1

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.

Changed January 28, 2011 12:41PM UTC by jitter comment:2

milestone: 1.next1.4.3

Changed January 28, 2011 01:37PM UTC by jiles@snagajob.com comment:3

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

Changed January 29, 2011 04:46AM UTC by jitter comment:4

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.