extend load funcion
extend load funcion
I need a bar of individual progress in my site, where diverse divs is
loaded at the same time after consults. As this is a common thing
excessively, I find pertinent that it is part of the functionality
standard of the function load. Something that very is not complicated
to make, and nor harms the performance and the same I did not see I
how to make it without modifying jquery nor making strange codes.
Follows the modification and the example.
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,
container: this, //This is my trick!
ifModified: ifModified,
complete: function(res, status){
if ( status == "success" || !ifModified && status ==
"notmodified" )
// Inject the HTML into all the matched elements
self.attr("innerHTML", res.responseText)
// Execute all the scripts inside of the newly-injected HTML
.evalScripts()
// Execute callback
.each( callback, [res.responseText, status, res] );
else
callback.apply( self, [res.responseText, status, res] );
}
});
return this;
},
/////////////////////////////////////////////////////////////////
/////////////////exemple
$(function()
{
$.ajaxSetup({beforeSend:
function()
{this.container.html('loading...');}
});
$('#button').click(
function()
{
$('#divcontainer').load('data.html')
});
});
////////////////////////////////////////////////////////
Understand?
Independent of my alteration to be accepted, I go to use it in my
site. In case that somebody has a solution for problem the same, I
will be grateful.