- var t = "GET";
- if ( o && o.constructor == Function ) {
- f = o;
- o = null;
- }
- if (o != null) {
- o = $.param(o);
- t = "POST";
- }
- var self = this;
- $.xml(t,a,o,function(h){
- var h = h.responseText;
- self.html(h).find("script").each(function(){
- try {
- eval( this.text || this.textContent || this.innerHTML );
- } catch(e){}
- });
- if(f)f(h);
- });
- return this;
+ // Open the socket
+ xml.open(type || "GET", url, true);
+
+ // Set the correct header, if data is being sent
+ if ( data )
+ xml.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
+
+ // Set header so calling script knows that it's an XMLHttpRequest
+ xml.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
+
+ // Make sure the browser sends the right content length
+ if ( xml.overrideMimeType )
+ xml.setRequestHeader('Connection', 'close');
+
+ // Wait for a response to come back
+ xml.onreadystatechange = function(){
+ // Socket is openend
+ if ( xml.readyState == 1 ) {
+ // Increase counter
+ $.xmlActive++;
+
+ // Show loader if needed
+ if ( $.xmlActive >= 1 && $.xmlCreate )
+ $.event.trigger( 'ajaxStart' );
+ }
+
+ // Socket is closed and data is available
+ if ( xml.readyState == 4 ) {
+ // Decrease counter
+ $.xmlActive--;
+
+ // Hide loader if needed
+ if ( $.xmlActive <= 0 && $.xmlDestroy ) {
+ $.event.trigger( 'ajaxComplete' );
+ $.xmlActive = 0
+ }
+
+ // Make sure that the request was successful
+ if ( $.httpSuccess( xml ) ) {
+
+ // If a local callback was specified, fire it
+ if ( success ) success( xml );
+
+ // Fire the global callback
+ $.event.trigger( 'ajaxSuccess' );
+
+ // Otherwise, the request was not successful
+ } else {
+ // If a local callback was specified, fire it
+ if ( error ) error( xml );
+
+ // Fire the global callback
+ $.event.trigger( 'ajaxError' );
+ }
+
+ // Process result
+ if ( ret ) ret(xml);
+ }
+ };
+
+ // Send the data
+ xml.send(data);