Bug Tracker

Ticket #4235 (closed bug: fixed)

Opened 6 years ago

Last modified 5 years ago

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

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

Description

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

comment:1 Changed 6 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 5 years ago by dmethvin

  • Component changed from unfilled to ajax

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 5 years ago by john

  • Status changed from new to closed
  • Resolution set to fixed
Note: See TracTickets for help on using tickets.