-if ( typeof XMLHttpRequest == 'undefined' && typeof window.ActiveXObject == 'function') {
- XMLHttpRequest = function() {
- return new ActiveXObject((navigator.userAgent.toLowerCase().indexOf('msie 5') >= 0) ?
- "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP");
- };
-}
+/**
+ * Load HTML from a remote file and inject it into the DOM
+ */
+jQuery.fn.load = function( url, params, callback ) {
+ // I overwrote the event plugin's .load
+ // this won't happen again, I hope -John
+ if ( url && url.constructor == Function )
+ return this.bind("load", url);
+
+ // Default to a GET request
+ var type = "GET";
+
+ // If the second parameter was provided
+ if ( params ) {
+ // If it's a function
+ if ( params.constructor == Function ) {
+ // 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( type, url, params,function(res){
+
+ // Inject the HTML into all the matched elements
+ self.html(res.responseText).each(function(){
+ // If a callback function was provided
+ if ( callback && callback.constructor == Function )
+ // Execute it within the context of the element
+ callback.apply( self, [res.responseText] );
+ });
+
+ // Execute all the scripts inside of the newly-injected HTML
+ $("script", self).each(function(){
+ eval( this.text || this.textContent || this.innerHTML || "");
+ });