Modify ↓
Ticket #4235 (closed bug: fixed)
$('#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:2 Changed 4 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.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

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?