removed the test for bug #164, the test suite is unable to handle the resulting error...
[jquery.git] / src / ajax / ajax.js
1 jQuery.fn.extend({
2
3         /**
4          * Load HTML from a remote file and inject it into the DOM, only if it's
5          * been modified by the server.
6          *
7          * @example $("#feeds").loadIfModified("feeds.html")
8          * @before <div id="feeds"></div>
9          * @result <div id="feeds"><b>45</b> feeds found.</div>
10          *
11          * @name loadIfModified
12          * @type jQuery
13          * @param String url The URL of the HTML file to load.
14          * @param Hash params A set of key/value pairs that will be sent to the server.
15          * @param Function callback A function to be executed whenever the data is loaded.
16          * @cat AJAX
17          */
18         loadIfModified: function( url, params, callback ) {
19                 this.load( url, params, callback, 1 );
20         },
21
22         /**
23          * Load HTML from a remote file and inject it into the DOM.
24          *
25          * @example $("#feeds").load("feeds.html")
26          * @before <div id="feeds"></div>
27          * @result <div id="feeds"><b>45</b> feeds found.</div>
28          *
29          * @example $("#feeds").load("feeds.html",
30          *   {test: true},
31          *   function() { alert("load is done"); }
32          * );
33          * @desc Same as above, but with an additional parameter
34          * and a callback that is executed when the data was loaded.
35          *
36          * @test stop();
37          * $('#first').load("data/name.php", function() {
38          *      ok( $('#first').text() == 'ERROR', 'Check if content was injected into the DOM' );
39          *      start();
40          * });
41          *
42          * @name load
43          * @type jQuery
44          * @param String url The URL of the HTML file to load.
45          * @param Hash params A set of key/value pairs that will be sent to the server.
46          * @param Function callback A function to be executed whenever the data is loaded.
47          * @cat AJAX
48          */
49         load: function( url, params, callback, ifModified ) {
50                 if ( url.constructor == Function )
51                         return this.bind("load", url);
52         
53                 callback = callback || function(){};
54         
55                 // Default to a GET request
56                 var type = "GET";
57         
58                 // If the second parameter was provided
59                 if ( params ) {
60                         // If it's a function
61                         if ( params.constructor == Function ) {
62                                 // We assume that it's the callback
63                                 callback = params;
64                                 params = null;
65                                 
66                         // Otherwise, build a param string
67                         } else {
68                                 params = jQuery.param( params );
69                                 type = "POST";
70                         }
71                 }
72                 
73                 var self = this;
74                 
75                 // Request the remote document
76                 jQuery.ajax( type, url, params,function(res, status){
77                         
78                         if ( status == "success" || !ifModified && status == "notmodified" ) {
79                                 // Inject the HTML into all the matched elements
80                                 self.html(res.responseText).each( callback, [res.responseText, status] );
81                                 
82                                 // Execute all the scripts inside of the newly-injected HTML
83                                 $("script", self).each(function(){
84                                         if ( this.src )
85                                                 $.getScript( this.src );
86                                         else
87                                                 eval.call( window, this.text || this.textContent || this.innerHTML || "" );
88                                 });
89                         } else
90                                 callback.apply( self, [res.responseText, status] );
91         
92                 }, ifModified);
93                 
94                 return this;
95         },
96
97         /**
98          * Serializes a set of input elements into a string of data.
99          * This will serialize all given elements. If you need 
100          * serialization similar to the form submit of a browser,
101          * you should use the form plugin. This is also true for
102          * selects with multiple attribute set, only a single option
103          * is serialized.
104          *
105          * @example $("input[@type=text]").serialize();
106          * @before <input type='text' name='name' value='John'/>
107          * <input type='text' name='location' value='Boston'/>
108          * @after name=John&location=Boston
109          * @desc Serialize a selection of input elements to a string
110          *
111          * @test var data = $(':input').not('button').serialize();
112          * // ignore button, IE takes text content as value, not relevant for this test
113          * ok( data == 'action=Test&text2=Test&radio1=on&radio2=on&check=on&=on&hidden=&foo[bar]=&name=name&=foobar&select1=&select2=3&select3=1', 'Check form serialization as query string' );
114          *
115          * @name serialize
116          * @type String
117          * @cat AJAX
118          */
119         serialize: function() {
120                 return $.param( this );
121         }
122         
123 });
124
125 // If IE is used, create a wrapper for the XMLHttpRequest object
126 if ( jQuery.browser.msie && typeof XMLHttpRequest == "undefined" )
127         XMLHttpRequest = function(){
128                 return new ActiveXObject(
129                         navigator.userAgent.indexOf("MSIE 5") >= 0 ?
130                         "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP"
131                 );
132         };
133
134 // Attach a bunch of functions for handling common AJAX events
135
136 /**
137  * Attach a function to be executed whenever an AJAX request begins.
138  *
139  * @example $("#loading").ajaxStart(function(){
140  *   $(this).show();
141  * });
142  * @desc Show a loading message whenever an AJAX request starts.
143  *
144  * @name ajaxStart
145  * @type jQuery
146  * @param Function callback The function to execute.
147  * @cat AJAX
148  */
149  
150 /**
151  * Attach a function to be executed whenever all AJAX requests have ended.
152  *
153  * @example $("#loading").ajaxStop(function(){
154  *   $(this).hide();
155  * });
156  * @desc Hide a loading message after all the AJAX requests have stopped.
157  *
158  * @name ajaxStop
159  * @type jQuery
160  * @param Function callback The function to execute.
161  * @cat AJAX
162  */
163  
164 /**
165  * Attach a function to be executed whenever an AJAX request completes.
166  *
167  * @example $("#msg").ajaxComplete(function(){
168  *   $(this).append("<li>Request Complete.</li>");
169  * });
170  * @desc Show a message when an AJAX request completes.
171  *
172  * @name ajaxComplete
173  * @type jQuery
174  * @param Function callback The function to execute.
175  * @cat AJAX
176  */
177  
178 /**
179  * Attach a function to be executed whenever an AJAX request completes
180  * successfully.
181  *
182  * @example $("#msg").ajaxSuccess(function(){
183  *   $(this).append("<li>Successful Request!</li>");
184  * });
185  * @desc Show a message when an AJAX request completes successfully.
186  *
187  * @name ajaxSuccess
188  * @type jQuery
189  * @param Function callback The function to execute.
190  * @cat AJAX
191  */
192  
193 /**
194  * Attach a function to be executed whenever an AJAX request fails.
195  *
196  * @example $("#msg").ajaxError(function(){
197  *   $(this).append("<li>Error requesting page.</li>");
198  * });
199  * @desc Show a message when an AJAX request fails.
200  *
201  * @name ajaxError
202  * @type jQuery
203  * @param Function callback The function to execute.
204  * @cat AJAX
205  */
206  
207 /**
208  * @test stop(); var counter = { complete: 0, success: 0, error: 0 };
209  * var success = function() { counter.success++ };
210  * var error = function() { counter.error++ };
211  * var complete = function() { counter.complete++ };
212  * $('#foo').ajaxStart(complete).ajaxStop(complete).ajaxComplete(complete).ajaxError(error).ajaxSuccess(success);
213  * // start with successful test
214  * $.ajax({url: "data/name.php", success: success, error: error, complete: function() {
215  *   ok( counter.error == 0, 'Check succesful request' );
216  *   ok( counter.success == 2, 'Check succesful request' );
217  *   ok( counter.complete == 3, 'Check succesful request' );
218  *   counter.error = 0; counter.success = 0; counter.complete = 0;
219  *   $.ajaxTimeout(500);
220  *   $.ajax({url: "data/name.php?wait=5", success: success, error: error, complete: function() {
221  *     ok( counter.error == 2, 'Check failed request' );
222  *     ok( counter.success == 0, 'Check failed request' );
223  *     ok( counter.complete == 3, 'Check failed request' );
224  *     start();
225  *   }});
226  * }});
227  
228  * @test stop(); var counter = { complete: 0, success: 0, error: 0 };
229  * counter.error = 0; counter.success = 0; counter.complete = 0;
230  * var success = function() { counter.success++ };
231  * var error = function() { counter.error++ };
232  * $.ajaxTimeout(0);
233  * $.ajax({url: "data/name.php", global: false, success: success, error: error, complete: function() {
234  *   ok( counter.error == 0, 'Check sucesful request without globals' );
235  *   ok( counter.success == 1, 'Check sucesful request without globals' );
236  *   ok( counter.complete == 0, 'Check sucesful request without globals' );
237  *   counter.error = 0; counter.success = 0; counter.complete = 0;
238  *   $.ajaxTimeout(500);
239  *   $.ajax({url: "data/name.php?wait=5", global: false, success: success, error: error, complete: function() {
240  *      ok( counter.error == 1, 'Check failed request without globals' );
241  *      ok( counter.success == 0, 'Check failed request without globals' );
242  *      ok( counter.complete == 0, 'Check failed request without globals' );
243  *      start();
244  *   }});
245  * }});
246  * 
247  * @name ajaxHandlersTesting
248  * @private
249  */
250  
251
252 new function(){
253         var e = "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess".split(",");
254         
255         for ( var i = 0; i < e.length; i++ ) new function(){
256                 var o = e[i];
257                 jQuery.fn[o] = function(f){
258                         return this.bind(o, f);
259                 };
260         };
261 };
262
263 jQuery.extend({
264
265         /**
266          * Load a remote page using an HTTP GET request. All of the arguments to
267          * the method (except URL) are optional.
268          *
269          * @example $.get("test.cgi")
270          *
271          * @example $.get("test.cgi", { name: "John", time: "2pm" } )
272          *
273          * @example $.get("test.cgi", function(data){
274          *   alert("Data Loaded: " + data);
275          * })
276          *
277          * @example $.get("test.cgi",
278          *   { name: "John", time: "2pm" },
279          *   function(data){
280          *     alert("Data Loaded: " + data);
281          *   }
282          * )
283          *
284          * @name $.get
285          * @type jQuery
286          * @param String url The URL of the page to load.
287          * @param Hash params A set of key/value pairs that will be sent to the server.
288          * @param Function callback A function to be executed whenever the data is loaded.
289          * @cat AJAX
290          */
291         get: function( url, data, callback, type, ifModified ) {
292                 if ( data.constructor == Function ) {
293                         type = callback;
294                         callback = data;
295                         data = null;
296                 }
297                 
298                 // append ? + data or & + data, in case there are already params
299                 if ( data ) url += ((url.indexOf("?") > -1) ? "&" : "?") + jQuery.param(data);
300                 
301                 // Build and start the HTTP Request
302                 jQuery.ajax( "GET", url, null, function(r, status) {
303                         if ( callback ) callback( jQuery.httpData(r,type), status );
304                 }, ifModified);
305         },
306         
307         /**
308          * Load a remote page using an HTTP GET request, only if it hasn't
309          * been modified since it was last retrieved. All of the arguments to
310          * the method (except URL) are optional.
311          *
312          * @example $.getIfModified("test.html")
313          *
314          * @example $.getIfModified("test.html", { name: "John", time: "2pm" } )
315          *
316          * @example $.getIfModified("test.cgi", function(data){
317          *   alert("Data Loaded: " + data);
318          * })
319          *
320          * @example $.getifModified("test.cgi",
321          *   { name: "John", time: "2pm" },
322          *   function(data){
323          *     alert("Data Loaded: " + data);
324          *   }
325          * )
326          *
327          * @test stop();
328          * $.getIfModified("data/name.php", function(msg) {
329          *     ok( msg == 'ERROR', 'Check ifModified' );
330          *     start();
331          * });
332          *
333          * @name $.getIfModified
334          * @type jQuery
335          * @param String url The URL of the page to load.
336          * @param Hash params A set of key/value pairs that will be sent to the server.
337          * @param Function callback A function to be executed whenever the data is loaded.
338          * @cat AJAX
339          */
340         getIfModified: function( url, data, callback, type ) {
341                 jQuery.get(url, data, callback, type, 1);
342         },
343
344         /**
345          * Loads, and executes, a remote JavaScript file using an HTTP GET request.
346          * All of the arguments to the method (except URL) are optional.
347          *
348          * @example $.getScript("test.js")
349          *
350          * @example $.getScript("test.js", function(){
351          *   alert("Script loaded and executed.");
352          * })
353          *
354          * @test stop();
355          * $.getScript("data/test.js", function() {
356          *      ok( foobar == "bar", 'Check if script was evaluated' );
357          *      start();
358          * });
359          *
360          * @name $.getScript
361          * @type jQuery
362          * @param String url The URL of the page to load.
363          * @param Function callback A function to be executed whenever the data is loaded.
364          * @cat AJAX
365          */
366         getScript: function( url, callback ) {
367                 jQuery.get(url, callback, "script");
368         },
369         
370         /**
371          * Load a remote JSON object using an HTTP GET request.
372          * All of the arguments to the method (except URL) are optional.
373          *
374          * @example $.getJSON("test.js", function(json){
375          *   alert("JSON Data: " + json.users[3].name);
376          * })
377          *
378          * @example $.getJSON("test.js",
379          *   { name: "John", time: "2pm" },
380          *   function(json){
381          *     alert("JSON Data: " + json.users[3].name);
382          *   }
383          * )
384          *
385          * @test stop();
386          * $.getJSON("data/json.php", {json: "array"}, function(json) {
387          *   ok( json[0].name == 'John', 'Check JSON: first, name' );
388          *   ok( json[0].age == 21, 'Check JSON: first, age' );
389          *   ok( json[1].name == 'Peter', 'Check JSON: second, name' );
390          *   ok( json[1].age == 25, 'Check JSON: second, age' );
391          *   start();
392          * });
393          * @test stop();
394          * $.getJSON("data/json.php", function(json) {
395          *   ok( json.data.lang == 'en', 'Check JSON: lang' );
396          *   ok( json.data.length == 25, 'Check JSON: length' );
397          *   start();
398          * });
399          *
400          * @name $.getJSON
401          * @type jQuery
402          * @param String url The URL of the page to load.
403          * @param Hash params A set of key/value pairs that will be sent to the server.
404          * @param Function callback A function to be executed whenever the data is loaded.
405          * @cat AJAX
406          */
407         getJSON: function( url, data, callback ) {
408                 if(callback)
409                         jQuery.get(url, data, callback, "json");
410                 else {
411                         jQuery.get(url, data, "json");
412                 }
413         },
414         
415         /**
416          * Load a remote page using an HTTP POST request. All of the arguments to
417          * the method (except URL) are optional.
418          *
419          * @example $.post("test.cgi")
420          *
421          * @example $.post("test.cgi", { name: "John", time: "2pm" } )
422          *
423          * @example $.post("test.cgi", function(data){
424          *   alert("Data Loaded: " + data);
425          * })
426          *
427          * @example $.post("test.cgi",
428          *   { name: "John", time: "2pm" },
429          *   function(data){
430          *     alert("Data Loaded: " + data);
431          *   }
432          * )
433          *
434          * @test stop();
435          * $.post("data/name.php", {xml: "5-2"}, function(xml){
436          *   $('math', xml).each(function() {
437          *          ok( $('calculation', this).text() == '5-2', 'Check for XML' );
438          *          ok( $('result', this).text() == '3', 'Check for XML' );
439          *       });
440          *   start();
441          * });
442          *
443          * @name $.post
444          * @type jQuery
445          * @param String url The URL of the page to load.
446          * @param Hash params A set of key/value pairs that will be sent to the server.
447          * @param Function callback A function to be executed whenever the data is loaded.
448          * @cat AJAX
449          */
450         post: function( url, data, callback, type ) {
451                 // Build and start the HTTP Request
452                 jQuery.ajax( "POST", url, jQuery.param(data), function(r, status) {
453                         if ( callback ) callback( jQuery.httpData(r,type), status );
454                 });
455         },
456         
457         // timeout (ms)
458         timeout: 0,
459
460         /**
461          * Set the timeout of all AJAX requests to a specific amount of time.
462          * This will make all future AJAX requests timeout after a specified amount
463          * of time (the default is no timeout).
464          *
465          * @example $.ajaxTimeout( 5000 );
466          * @desc Make all AJAX requests timeout after 5 seconds.
467          *
468          * @test stop();
469          * var passed = 0;
470          * var timeout;
471          * $.ajaxTimeout(1000);
472          * var pass = function() {
473          *      passed++;
474          *      if(passed == 2) {
475          *              ok( true, 'Check local and global callbacks after timeout' );
476          *              clearTimeout(timeout);
477          *      $('#main').unbind("ajaxError");
478          *              start();
479          *      }
480          * };
481          * var fail = function() {
482          *      ok( false, 'Check for timeout failed' );
483          *      start();
484          * };
485          * timeout = setTimeout(fail, 1500);
486          * $('#main').ajaxError(pass);
487          * $.ajax({
488          *   type: "GET",
489          *   url: "data/name.php?wait=5",
490          *   error: pass,
491          *   success: fail
492          * });
493          *
494          * @test stop(); $.ajaxTimeout(50);
495          * $.ajax({
496          *   type: "GET",
497          *   timeout: 5000,
498          *   url: "data/name.php?wait=1",
499          *   error: function() {
500          *         ok( false, 'Check for local timeout failed' );
501          *         start();
502          *   },
503          *   success: function() {
504          *     ok( true, 'Check for local timeout' );
505          *     start();
506          *   }
507          * });
508          * // reset timeout
509          * $.ajaxTimeout(0);
510          * 
511          *
512          * @name $.ajaxTimeout
513          * @type jQuery
514          * @param Number time How long before an AJAX request times out.
515          * @cat AJAX
516          */
517         ajaxTimeout: function(timeout) {
518                 jQuery.timeout = timeout;
519         },
520
521         // Last-Modified header cache for next request
522         lastModified: {},
523         
524         /**
525          * Load a remote page using an HTTP request. This function is the primary
526          * means of making AJAX requests using jQuery. $.ajax() takes one property,
527          * an object of key/value pairs, that're are used to initalize the request.
528          *
529          * These are all the key/values that can be passed in to 'prop':
530          *
531          * (String) type - The type of request to make (e.g. "POST" or "GET").
532          *
533          * (String) url - The URL of the page to request.
534          * 
535          * (String) data - A string of data to be sent to the server (POST only).
536          *
537          * (String) dataType - The type of data that you're expecting back from
538          * the server (e.g. "xml", "html", "script", or "json").
539          *
540          * (Boolean) ifModified - Allow the request to be successful only if the
541          * response has changed since the last request, default is false, ignoring
542          * the Last-Modified header
543          *
544          * (Number) timeout - Local timeout to override global timeout, eg. to give a
545          * single request a longer timeout while all others timeout after 1 seconds,
546          * see $.ajaxTimeout
547          *
548          * (Boolean) global - Wheather to trigger global AJAX event handlers for
549          * this request, default is true. Set to true to prevent that global handlers
550          * like ajaxStart or ajaxStop are triggered.
551          *
552          * (Function) error - A function to be called if the request fails. The
553          * function gets passed two arguments: The XMLHttpRequest object and a
554          * string describing the type of error that occurred.
555          *
556          * (Function) success - A function to be called if the request succeeds. The
557          * function gets passed one argument: The data returned from the server,
558          * formatted according to the 'dataType' parameter.
559          *
560          * (Function) complete - A function to be called when the request finishes. The
561          * function gets passed two arguments: The XMLHttpRequest object and a
562          * string describing the type the success of the request.
563          *
564          * @example $.ajax({
565          *   type: "GET",
566          *   url: "test.js",
567          *   dataType: "script"
568          * })
569          * @desc Load and execute a JavaScript file.
570          *
571          * @example $.ajax({
572          *   type: "POST",
573          *   url: "some.php",
574          *   data: "name=John&location=Boston",
575          *   success: function(msg){
576          *     alert( "Data Saved: " + msg );
577          *   }
578          * });
579          * @desc Save some data to the server and notify the user once its complete.
580          *
581          * @test stop();
582          * $.ajax({
583          *   type: "GET",
584          *   url: "data/name.php?name=foo",
585          *   success: function(msg){
586          *     ok( msg == 'bar', 'Check for GET' );
587          *     start();
588          *   }
589          * });
590          *
591          * @test stop();
592          * $.ajax({
593          *   type: "POST",
594          *   url: "data/name.php",
595          *   data: "name=peter",
596          *   success: function(msg){
597          *     ok( msg == 'pan', 'Check for POST' );
598          *     start();
599          *   }
600          * });
601          *
602          * @name $.ajax
603          * @type jQuery
604          * @param Hash prop A set of properties to initialize the request with.
605          * @cat AJAX
606          */
607         ajax: function( type, url, data, ret, ifModified ) {
608                 // If only a single argument was passed in,
609                 // assume that it is a object of key/value pairs
610                 if ( !url ) {
611                         ret = type.complete;
612                         var success = type.success;
613                         var error = type.error;
614                         var dataType = type.dataType;
615                         var global = typeof type.global == "boolean" ? type.global : true;
616                         var timeout = typeof type.timeout == "number" ? type.timeout : jQuery.timeout;
617                         var ifModified = type.ifModified || false;
618                         data = type.data;
619                         url = type.url;
620                         type = type.type;
621                 }
622                 
623                 // Watch for a new set of requests
624                 if ( global && ! jQuery.active++ )
625                         jQuery.event.trigger( "ajaxStart" );
626
627                 var requestDone = false;
628         
629                 // Create the request object
630                 var xml = new XMLHttpRequest();
631         
632                 // Open the socket
633                 xml.open(type || "GET", url, true);
634                 
635                 // Set the correct header, if data is being sent
636                 if ( data )
637                         xml.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
638                 
639                 // Set the If-Modified-Since header, if ifModified mode.
640                 if ( ifModified )
641                         xml.setRequestHeader("If-Modified-Since",
642                                 jQuery.lastModified[url] || "Thu, 01 Jan 1970 00:00:00 GMT" );
643                 
644                 // Set header so the called script knows that it's an XMLHttpRequest
645                 xml.setRequestHeader("X-Requested-With", "XMLHttpRequest");
646         
647                 // Make sure the browser sends the right content length
648                 if ( xml.overrideMimeType )
649                         xml.setRequestHeader("Connection", "close");
650                 
651                 // Wait for a response to come back
652                 var onreadystatechange = function(istimeout){
653                         // The transfer is complete and the data is available, or the request timed out
654                         if ( xml && (xml.readyState == 4 || istimeout == "timeout") ) {
655                                 requestDone = true;
656
657                                 var status = jQuery.httpSuccess( xml ) && istimeout != "timeout" ?
658                                         ifModified && jQuery.httpNotModified( xml, url ) ? "notmodified" : "success" : "error";
659                                 
660                                 // Make sure that the request was successful or notmodified
661                                 if ( status != "error" ) {
662                                         // Cache Last-Modified header, if ifModified mode.
663                                         var modRes;
664                                         try {
665                                                 modRes = xml.getResponseHeader("Last-Modified");
666                                         } catch(e) {} // swallow exception thrown by FF if header is not available
667                                         
668                                         if ( ifModified && modRes )
669                                                 jQuery.lastModified[url] = modRes;
670                                         
671                                         // If a local callback was specified, fire it
672                                         if ( success )
673                                                 success( jQuery.httpData( xml, dataType ), status );
674                                         
675                                         // Fire the global callback
676                                         if( global )
677                                                 jQuery.event.trigger( "ajaxSuccess" );
678                                 
679                                 // Otherwise, the request was not successful
680                                 } else {
681                                         // If a local callback was specified, fire it
682                                         if ( error ) error( xml, status );
683                                         
684                                         // Fire the global callback
685                                         if( global )
686                                                 jQuery.event.trigger( "ajaxError" );
687                                 }
688                                 
689                                 // The request was completed
690                                 if( global )
691                                         jQuery.event.trigger( "ajaxComplete" );
692                                 
693                                 // Handle the global AJAX counter
694                                 if ( global && ! --jQuery.active )
695                                         jQuery.event.trigger( "ajaxStop" );
696         
697                                 // Process result
698                                 if ( ret ) ret(xml, status);
699                                 
700                                 // Stop memory leaks
701                                 xml.onreadystatechange = function(){};
702                                 xml = null;
703                                 
704                         }
705                 };
706                 xml.onreadystatechange = onreadystatechange;
707                 
708                 // Timeout checker
709                 if(timeout > 0)
710                         setTimeout(function(){
711                                 // Check to see if the request is still happening
712                                 if (xml) {
713                                         // Cancel the request
714                                         xml.abort();
715
716                                         if ( !requestDone ) onreadystatechange( "timeout" );
717
718                                         // Clear from memory
719                                         xml = null;
720                                 }
721                         }, timeout);
722                 
723                 // Send the data
724                 xml.send(data);
725         },
726         
727         // Counter for holding the number of active queries
728         active: 0,
729         
730         // Determines if an XMLHttpRequest was successful or not
731         httpSuccess: function(r) {
732                 try {
733                         return !r.status && location.protocol == "file:" ||
734                                 ( r.status >= 200 && r.status < 300 ) || r.status == 304 ||
735                                 jQuery.browser.safari && r.status == undefined;
736                 } catch(e){}
737
738                 return false;
739         },
740
741         // Determines if an XMLHttpRequest returns NotModified
742         httpNotModified: function(xml, url) {
743                 try {
744                         var xmlRes = xml.getResponseHeader("Last-Modified");
745
746                         // Firefox always returns 200. check Last-Modified date
747                         return xml.status == 304 || xmlRes == jQuery.lastModified[url] ||
748                                 jQuery.browser.safari && xml.status == undefined;
749                 } catch(e){}
750
751                 return false;
752         },
753         
754         /* Get the data out of an XMLHttpRequest.
755          * Return parsed XML if content-type header is "xml" and type is "xml" or omitted,
756          * otherwise return plain text.
757          * (String) data - The type of data that you're expecting back,
758          * (e.g. "xml", "html", "script")
759          */
760         httpData: function(r,type) {
761                 var ct = r.getResponseHeader("content-type");
762                 var data = !type && ct && ct.indexOf("xml") >= 0;
763                 data = type == "xml" || data ? r.responseXML : r.responseText;
764
765                 // If the type is "script", eval it
766                 if ( type == "script" ) eval.call( window, data );
767
768                 // Get the JavaScript object, if JSON is used.
769                 if ( type == "json" ) eval( "data = " + data );
770
771                 return data;
772         },
773         
774         // Serialize an array of form elements or a set of
775         // key/values into a query string
776         param: function(a) {
777                 var s = [];
778                 
779                 // If an array was passed in, assume that it is an array
780                 // of form elements
781                 if ( a.constructor == Array || a.jquery ) {
782                         // Serialize the form elements
783                         for ( var i = 0; i < a.length; i++ )
784                                 s.push( a[i].name + "=" + encodeURIComponent( a[i].value ) );
785                         
786                 // Otherwise, assume that it's an object of key/value pairs
787                 } else {
788                         // Serialize the key/values
789                         for ( var j in a )
790                                 s.push( j + "=" + encodeURIComponent( a[j] ) );
791                 }
792                 
793                 // Return the resulting serialization
794                 return s.join("&");
795         }
796
797 });