[jQuery] Please review my micro-plugin for a perceived hole in the jQuery API
Does anyone see a problem with this? Has anyone else had to implement
something similar? Why wasn't something like this included with
jQuery?
/**
* An AJAX extender for jQuery.fn.
*
* jQuery's low-level ajax implementation can handle every scenario
EXCEPT the situations where we want to apply
* AJAX results directly to a DOM element; Curiously, jQuery has a
method that handles this, however, it isn't
* compatible with the advanced jQuery.ajax() method:
*
* jQuery( selector ).load( url )
*
* Therefore, this plugin was meant to plug a perceived hole in the
jQuery API by providing the following method:
*
* jQuery( selector ).ajax( ajaxOptions )
*
* @param ajaxOptions object jQuery AJAX-options. Note, if a
"success" property is defined, it'll be overwritten by this plugin.
* @return jQuery collection
*/
(function(){
jQuery.fn.ajax = function( ajaxOptions )
{
var that = this;
var success = function success_cb( data, textStatus )
{
that.html( data );
}
var ajaxOptions = jQuery.extend( {}, { success: success },
ajaxOptions );
return jQuery.ajax( ajaxOptions );
}
})();