- // 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(){
- // The transfer is complete and the data is available
- if ( xml.readyState == 4 ) {
- // Make sure that the request was successful
- if ( jQuery.httpSuccess( xml ) ) {
-
- // If a local callback was specified, fire it
- if ( success ) success( xml );
+ /**
+ * Load a remote page using a POST request.
+ */
+ post: function( url, data, callback, type ) {
+ // Build and start the HTTP Request
+ jQuery.ajax( "POST", url, jQuery.param(data), function(r) {
+ if ( callback ) callback( jQuery.httpData(r,type) );
+ });
+ },
+
+ /**
+ * A common wrapper for making XMLHttpRequests
+ */
+ ajax: function( type, url, data, ret ) {
+ // If only a single argument was passed in,
+ // assume that it is a object of key/value pairs
+ if ( !url ) {
+ ret = type.complete;
+ var success = type.success;
+ var error = type.error;
+ data = type.data;
+ url = type.url;
+ type = type.type;
+ }
+
+ // Watch for a new set of requests
+ if ( ! jQuery.active++ )
+ jQuery.event.trigger( "ajaxStart" );
+
+ // Create the request object
+ var xml = new XMLHttpRequest();
+
+ // 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(){
+ // The transfer is complete and the data is available
+ if ( xml.readyState == 4 ) {
+ // Make sure that the request was successful
+ if ( jQuery.httpSuccess( xml ) ) {