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