Skip to main content

Bug Tracker

Side navigation

#4235 closed bug (fixed)

Opened February 24, 2009 08:26PM UTC

Closed November 11, 2009 07:55PM UTC

$('#id).load() doesn't execute callback if selector matches an empty set

Reported by: Owned by:
Priority: major Milestone: 1.4
Component: ajax Version: 1.3.2
Keywords: Cc:
Blocked by: Blocking:

Discovered this due to a typo in my code. Consider

$('#id).load('stuff.html', {}, callback);

If there is no element named 'id' on the page, load -does- run, and firebug does assure me that stuff.html is requested

Attachments (0)
Change History (3)

Changed February 26, 2009 12:05AM UTC by dmethvin comment:1

That's understandable, since the docs for .load say the callback is called this way:

function (responseText, textStatus, XMLHttpRequest) {
  this; // dom element

If there are no elements in the jQuery object, the function can't be called because the

can't be given a value!

So are you requesting that if no elements are selected the ajax shouldn't happen at all? Or some other behavior?

Changed October 14, 2009 03:16AM UTC by dmethvin comment:2

component: unfilledajax

The OP didn't reply, but I think the only issue here is whether the ajax should happen if no elements are selected, but never call the callback. We should document it either way.

Changed November 11, 2009 07:55PM UTC by john comment:3

resolution: → fixed
status: newclosed