Bug Tracker

Opened 14 years ago

Closed 13 years ago

#4235 closed bug (fixed)

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

Reported by: [email protected] 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

Change History (3)

comment:1 Changed 14 years ago by dmethvin

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 this 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?

comment:2 Changed 13 years ago by dmethvin

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.

comment:3 Changed 13 years ago by john

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.