Trigger load event when complete ajax load
Hi!
I think would be nice trigger a load event when an ajax load is
complete. Am I wrong?
Thank you! jQuery is great!
load: function( url, params, callback, ifModified ) {
if ( jQuery.isFunction( url ) )
return this.bind("load", url);
callback = callback || function(){};
// Default to a GET request
var type = "GET";
// If the second parameter was provided
if ( params )
// If it's a function
if ( jQuery.isFunction( params ) ) {
// We assume that it's the callback
callback = params;
params = null;
// Otherwise, build a param string
} else {
params = jQuery.param( params );
type = "POST";
}
var self = this;
// Request the remote document
jQuery.ajax({
url: url,
type: type,
data: params,
ifModified: ifModified,
complete: function(res, status){
// If successful, inject the HTML into all the matched elements
if ( status == "success" || !ifModified && status ==
"notmodified" )
self.html(res.responseText);
// Add delay to account for Safari's delay in globalEval
setTimeout(function(){
self.each( callback, [res.responseText, status, res] );
}, 13);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
self.trigger("load", false);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
});
return this;
}