When I have a code like this:
$('#intro-posts-container').load('/ajax/load.php', function() {
bindVoting();
});
Does the load send the request to load.php, if the #intro-posts-container
element doesn't exist?
The jQuery load() method is a simple, but powerful AJAX method. The load() method loads data from a server and puts the returned data into the selected element.
The Load function initializes a database and loads it from an input data file. It can be used for initial loading of a database, as part of a database reorganization, or for reloading a database after changing the DBD definition.
get() executes an Ajax GET request. The returned data (which can be any data) will be passed to your callback handler. $(selector). load() will execute an Ajax GET request and will set the content of the selected returned data (which should be either text or HTML).
The load() method was deprecated in jQuery version 1.8 and removed in version 3.0. Use the on() or trigger() method instead.
A quick test in firebug on this page shows that it does not send the request if the element doesn't exist.
I've verified this from the source (v1.8.3), which contains the following:
jQuery.fn.load = function( url, params, callback ) {
// [snip]
// Don't do a request if no elements are being requested
if ( !this.length ) {
return this;
}
// [snip]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With