Upgrade to ExtJS 3.0.3 - Released 10/11/2009
[extjs.git] / docs / source / Connection.html
1 <html>
2 <head>
3   <title>The source code</title>
4     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
6 </head>
7 <body  onload="prettyPrint();">
8     <pre class="prettyprint lang-js">/*!
9  * Ext JS Library 3.0.3
10  * Copyright(c) 2006-2009 Ext JS, LLC
11  * licensing@extjs.com
12  * http://www.extjs.com/license
13  */
14 (function(){\r
15     var BEFOREREQUEST = "beforerequest",\r
16         REQUESTCOMPLETE = "requestcomplete",\r
17         REQUESTEXCEPTION = "requestexception",\r
18         UNDEFINED = undefined,\r
19         LOAD = 'load',\r
20         POST = 'POST',\r
21         GET = 'GET',\r
22         WINDOW = window;\r
23     \r
24     <div id="cls-Ext.data.Connection"></div>/**\r
25      * @class Ext.data.Connection\r
26      * @extends Ext.util.Observable\r
27      * <p>The class encapsulates a connection to the page's originating domain, allowing requests to be made\r
28      * either to a configured URL, or to a URL specified at request time.</p>\r
29      * <p>Requests made by this class are asynchronous, and will return immediately. No data from\r
30      * the server will be available to the statement immediately following the {@link #request} call.\r
31      * To process returned data, use a\r
32      * <a href="#request-option-success" ext:member="request-option-success" ext:cls="Ext.data.Connection">success callback</a>\r
33      * in the request options object,\r
34      * or an {@link #requestcomplete event listener}.</p>\r
35      * <p><h3>File Uploads</h3><a href="#request-option-isUpload" ext:member="request-option-isUpload" ext:cls="Ext.data.Connection">File uploads</a> are not performed using normal "Ajax" techniques, that\r
36      * is they are <b>not</b> performed using XMLHttpRequests. Instead the form is submitted in the standard\r
37      * manner with the DOM <tt>&lt;form></tt> element temporarily modified to have its\r
38      * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer\r
39      * to a dynamically generated, hidden <tt>&lt;iframe></tt> which is inserted into the document\r
40      * but removed after the return data has been gathered.</p>\r
41      * <p>The server response is parsed by the browser to create the document for the IFRAME. If the\r
42      * server is using JSON to send the return object, then the\r
43      * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">Content-Type</a> header\r
44      * must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.</p>\r
45      * <p>Characters which are significant to an HTML parser must be sent as HTML entities, so encode\r
46      * "&lt;" as "&amp;lt;", "&amp;" as "&amp;amp;" etc.</p>\r
47      * <p>The response text is retrieved from the document, and a fake XMLHttpRequest object\r
48      * is created containing a <tt>responseText</tt> property in order to conform to the\r
49      * requirements of event handlers and callbacks.</p>\r
50      * <p>Be aware that file upload packets are sent with the content type <a href="http://www.faqs.org/rfcs/rfc2388.html">multipart/form</a>\r
51      * and some server technologies (notably JEE) may require some custom processing in order to\r
52      * retrieve parameter names and parameter values from the packet content.</p>\r
53      * @constructor\r
54      * @param {Object} config a configuration object.\r
55      */\r
56     Ext.data.Connection = function(config){    \r
57         Ext.apply(this, config);\r
58         this.addEvents(\r
59             <div id="event-Ext.data.Connection-beforerequest"></div>/**\r
60              * @event beforerequest\r
61              * Fires before a network request is made to retrieve a data object.\r
62              * @param {Connection} conn This Connection object.\r
63              * @param {Object} options The options config object passed to the {@link #request} method.\r
64              */\r
65             BEFOREREQUEST,\r
66             <div id="event-Ext.data.Connection-requestcomplete"></div>/**\r
67              * @event requestcomplete\r
68              * Fires if the request was successfully completed.\r
69              * @param {Connection} conn This Connection object.\r
70              * @param {Object} response The XHR object containing the response data.\r
71              * See <a href="http://www.w3.org/TR/XMLHttpRequest/">The XMLHttpRequest Object</a>\r
72              * for details.\r
73              * @param {Object} options The options config object passed to the {@link #request} method.\r
74              */\r
75             REQUESTCOMPLETE,\r
76             <div id="event-Ext.data.Connection-requestexception"></div>/**\r
77              * @event requestexception\r
78              * Fires if an error HTTP status was returned from the server.\r
79              * See <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html">HTTP Status Code Definitions</a>\r
80              * for details of HTTP status codes.\r
81              * @param {Connection} conn This Connection object.\r
82              * @param {Object} response The XHR object containing the response data.\r
83              * See <a href="http://www.w3.org/TR/XMLHttpRequest/">The XMLHttpRequest Object</a>\r
84              * for details.\r
85              * @param {Object} options The options config object passed to the {@link #request} method.\r
86              */\r
87             REQUESTEXCEPTION\r
88         );\r
89         Ext.data.Connection.superclass.constructor.call(this);\r
90     };\r
91 \r
92     Ext.extend(Ext.data.Connection, Ext.util.Observable, {\r
93         <div id="cfg-Ext.data.Connection-url"></div>/**\r
94          * @cfg {String} url (Optional) <p>The default URL to be used for requests to the server. Defaults to undefined.</p>\r
95          * <p>The <code>url</code> config may be a function which <i>returns</i> the URL to use for the Ajax request. The scope\r
96          * (<code><b>this</b></code> reference) of the function is the <code>scope</code> option passed to the {@link #request} method.</p>\r
97          */\r
98         <div id="cfg-Ext.data.Connection-extraParams"></div>/**\r
99          * @cfg {Object} extraParams (Optional) An object containing properties which are used as\r
100          * extra parameters to each request made by this object. (defaults to undefined)\r
101          */\r
102         <div id="cfg-Ext.data.Connection-defaultHeaders"></div>/**\r
103          * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added\r
104          *  to each request made by this object. (defaults to undefined)\r
105          */\r
106         <div id="cfg-Ext.data.Connection-method"></div>/**\r
107          * @cfg {String} method (Optional) The default HTTP method to be used for requests.\r
108          * (defaults to undefined; if not set, but {@link #request} params are present, POST will be used;\r
109          * otherwise, GET will be used.)\r
110          */\r
111         <div id="cfg-Ext.data.Connection-timeout"></div>/**\r
112          * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)\r
113          */\r
114         timeout : 30000,\r
115         <div id="cfg-Ext.data.Connection-autoAbort"></div>/**\r
116          * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)\r
117          * @type Boolean\r
118          */\r
119         autoAbort:false,\r
120     \r
121         <div id="cfg-Ext.data.Connection-disableCaching"></div>/**\r
122          * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)\r
123          * @type Boolean\r
124          */\r
125         disableCaching: true,\r
126         \r
127         <div id="cfg-Ext.data.Connection-disableCachingParam"></div>/**\r
128          * @cfg {String} disableCachingParam (Optional) Change the parameter which is sent went disabling caching\r
129          * through a cache buster. Defaults to '_dc'\r
130          * @type String\r
131          */\r
132         disableCachingParam: '_dc',\r
133         \r
134         <div id="method-Ext.data.Connection-request"></div>/**\r
135          * <p>Sends an HTTP request to a remote server.</p>\r
136          * <p><b>Important:</b> Ajax server requests are asynchronous, and this call will\r
137          * return before the response has been received. Process any returned data\r
138          * in a callback function.</p>\r
139          * <pre><code>\r
140 Ext.Ajax.request({\r
141    url: 'ajax_demo/sample.json',\r
142    success: function(response, opts) {\r
143       var obj = Ext.decode(response.responseText);\r
144       console.dir(obj);\r
145    },\r
146    failure: function(response, opts) {\r
147       console.log('server-side failure with status code ' + response.status);\r
148    }\r
149 });\r
150          * </code></pre>\r
151          * <p>To execute a callback function in the correct scope, use the <tt>scope</tt> option.</p>\r
152          * @param {Object} options An object which may contain the following properties:<ul>\r
153          * <li><b>url</b> : String/Function (Optional)<div class="sub-desc">The URL to\r
154          * which to send the request, or a function to call which returns a URL string. The scope of the\r
155          * function is specified by the <tt>scope</tt> option. Defaults to the configured\r
156          * <tt>{@link #url}</tt>.</div></li>\r
157          * <li><b>params</b> : Object/String/Function (Optional)<div class="sub-desc">\r
158          * An object containing properties which are used as parameters to the\r
159          * request, a url encoded string or a function to call to get either. The scope of the function\r
160          * is specified by the <tt>scope</tt> option.</div></li>\r
161          * <li><b>method</b> : String (Optional)<div class="sub-desc">The HTTP method to use\r
162          * for the request. Defaults to the configured method, or if no method was configured,\r
163          * "GET" if no parameters are being sent, and "POST" if parameters are being sent.  Note that\r
164          * the method name is case-sensitive and should be all caps.</div></li>\r
165          * <li><b>callback</b> : Function (Optional)<div class="sub-desc">The\r
166          * function to be called upon receipt of the HTTP response. The callback is\r
167          * called regardless of success or failure and is passed the following\r
168          * parameters:<ul>\r
169          * <li><b>options</b> : Object<div class="sub-desc">The parameter to the request call.</div></li>\r
170          * <li><b>success</b> : Boolean<div class="sub-desc">True if the request succeeded.</div></li>\r
171          * <li><b>response</b> : Object<div class="sub-desc">The XMLHttpRequest object containing the response data. \r
172          * See <a href="http://www.w3.org/TR/XMLHttpRequest/">http://www.w3.org/TR/XMLHttpRequest/</a> for details about \r
173          * accessing elements of the response.</div></li>\r
174          * </ul></div></li>\r
175          * <li><a id="request-option-success"></a><b>success</b> : Function (Optional)<div class="sub-desc">The function\r
176          * to be called upon success of the request. The callback is passed the following\r
177          * parameters:<ul>\r
178          * <li><b>response</b> : Object<div class="sub-desc">The XMLHttpRequest object containing the response data.</div></li>\r
179          * <li><b>options</b> : Object<div class="sub-desc">The parameter to the request call.</div></li>\r
180          * </ul></div></li>\r
181          * <li><b>failure</b> : Function (Optional)<div class="sub-desc">The function\r
182          * to be called upon failure of the request. The callback is passed the\r
183          * following parameters:<ul>\r
184          * <li><b>response</b> : Object<div class="sub-desc">The XMLHttpRequest object containing the response data.</div></li>\r
185          * <li><b>options</b> : Object<div class="sub-desc">The parameter to the request call.</div></li>\r
186          * </ul></div></li>\r
187          * <li><b>scope</b> : Object (Optional)<div class="sub-desc">The scope in\r
188          * which to execute the callbacks: The "this" object for the callback function. If the <tt>url</tt>, or <tt>params</tt> options were\r
189          * specified as functions from which to draw values, then this also serves as the scope for those function calls.\r
190          * Defaults to the browser window.</div></li>\r
191          * <li><b>timeout</b> : Number (Optional)<div class="sub-desc">The timeout in milliseconds to be used for this request. Defaults to 30 seconds.</div></li>\r
192          * <li><b>form</b> : Element/HTMLElement/String (Optional)<div class="sub-desc">The <tt>&lt;form&gt;</tt>\r
193          * Element or the id of the <tt>&lt;form&gt;</tt> to pull parameters from.</div></li>\r
194          * <li><a id="request-option-isUpload"></a><b>isUpload</b> : Boolean (Optional)<div class="sub-desc"><b>Only meaningful when used \r
195          * with the <tt>form</tt> option</b>.\r
196          * <p>True if the form object is a file upload (will be set automatically if the form was\r
197          * configured with <b><tt>enctype</tt></b> "multipart/form-data").</p>\r
198          * <p>File uploads are not performed using normal "Ajax" techniques, that is they are <b>not</b>\r
199          * performed using XMLHttpRequests. Instead the form is submitted in the standard manner with the\r
200          * DOM <tt>&lt;form></tt> element temporarily modified to have its\r
201          * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer\r
202          * to a dynamically generated, hidden <tt>&lt;iframe></tt> which is inserted into the document\r
203          * but removed after the return data has been gathered.</p>\r
204          * <p>The server response is parsed by the browser to create the document for the IFRAME. If the\r
205          * server is using JSON to send the return object, then the\r
206          * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">Content-Type</a> header\r
207          * must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.</p>\r
208          * <p>The response text is retrieved from the document, and a fake XMLHttpRequest object\r
209          * is created containing a <tt>responseText</tt> property in order to conform to the\r
210          * requirements of event handlers and callbacks.</p>\r
211          * <p>Be aware that file upload packets are sent with the content type <a href="http://www.faqs.org/rfcs/rfc2388.html">multipart/form</a>\r
212          * and some server technologies (notably JEE) may require some custom processing in order to\r
213          * retrieve parameter names and parameter values from the packet content.</p>\r
214          * </div></li>\r
215          * <li><b>headers</b> : Object (Optional)<div class="sub-desc">Request\r
216          * headers to set for the request.</div></li>\r
217          * <li><b>xmlData</b> : Object (Optional)<div class="sub-desc">XML document\r
218          * to use for the post. Note: This will be used instead of params for the post\r
219          * data. Any params will be appended to the URL.</div></li>\r
220          * <li><b>jsonData</b> : Object/String (Optional)<div class="sub-desc">JSON\r
221          * data to use as the post. Note: This will be used instead of params for the post\r
222          * data. Any params will be appended to the URL.</div></li>\r
223          * <li><b>disableCaching</b> : Boolean (Optional)<div class="sub-desc">True\r
224          * to add a unique cache-buster param to GET requests.</div></li>\r
225          * </ul></p>\r
226          * <p>The options object may also contain any other property which might be needed to perform\r
227          * postprocessing in a callback because it is passed to callback functions.</p>\r
228          * @return {Number} transactionId The id of the server transaction. This may be used\r
229          * to cancel the request.\r
230          */\r
231         request : function(o){\r
232             var me = this;\r
233             if(me.fireEvent(BEFOREREQUEST, me, o)){\r
234                 if (o.el) {\r
235                     if(!Ext.isEmpty(o.indicatorText)){\r
236                         me.indicatorText = '<div class="loading-indicator">'+o.indicatorText+"</div>";\r
237                     }\r
238                     if(me.indicatorText) {\r
239                         Ext.getDom(o.el).innerHTML = me.indicatorText;                        \r
240                     }\r
241                     o.success = (Ext.isFunction(o.success) ? o.success : function(){}).createInterceptor(function(response) {\r
242                         Ext.getDom(o.el).innerHTML = response.responseText;\r
243                     });\r
244                 }\r
245                 \r
246                 var p = o.params,\r
247                     url = o.url || me.url,                \r
248                     method,\r
249                     cb = {success: me.handleResponse,\r
250                           failure: me.handleFailure,\r
251                           scope: me,\r
252                           argument: {options: o},\r
253                           timeout : o.timeout || me.timeout\r
254                     },\r
255                     form,                    \r
256                     serForm;                    \r
257                   \r
258                      \r
259                 if (Ext.isFunction(p)) {\r
260                     p = p.call(o.scope||WINDOW, o);\r
261                 }\r
262                                                            \r
263                 p = Ext.urlEncode(me.extraParams, Ext.isObject(p) ? Ext.urlEncode(p) : p);    \r
264                 \r
265                 if (Ext.isFunction(url)) {\r
266                     url = url.call(o.scope || WINDOW, o);\r
267                 }\r
268     \r
269                 if((form = Ext.getDom(o.form))){\r
270                     url = url || form.action;\r
271                      if(o.isUpload || /multipart\/form-data/i.test(form.getAttribute("enctype"))) { \r
272                          return me.doFormUpload.call(me, o, p, url);\r
273                      }\r
274                     serForm = Ext.lib.Ajax.serializeForm(form);                    \r
275                     p = p ? (p + '&' + serForm) : serForm;\r
276                 }\r
277                 \r
278                 method = o.method || me.method || ((p || o.xmlData || o.jsonData) ? POST : GET);\r
279                 \r
280                 if(method === GET && (me.disableCaching && o.disableCaching !== false) || o.disableCaching === true){\r
281                     var dcp = o.disableCachingParam || me.disableCachingParam;\r
282                     url = Ext.urlAppend(url, dcp + '=' + (new Date().getTime()));\r
283                 }\r
284                 \r
285                 o.headers = Ext.apply(o.headers || {}, me.defaultHeaders || {});\r
286                 \r
287                 if(o.autoAbort === true || me.autoAbort) {\r
288                     me.abort();\r
289                 }\r
290                  \r
291                 if((method == GET || o.xmlData || o.jsonData) && p){\r
292                     url = Ext.urlAppend(url, p);  \r
293                     p = '';\r
294                 }\r
295                 return (me.transId = Ext.lib.Ajax.request(method, url, cb, p, o));\r
296             }else{                \r
297                 return o.callback ? o.callback.apply(o.scope, [o,UNDEFINED,UNDEFINED]) : null;\r
298             }\r
299         },\r
300     \r
301         <div id="method-Ext.data.Connection-isLoading"></div>/**\r
302          * Determine whether this object has a request outstanding.\r
303          * @param {Number} transactionId (Optional) defaults to the last transaction\r
304          * @return {Boolean} True if there is an outstanding request.\r
305          */\r
306         isLoading : function(transId){\r
307             return transId ? Ext.lib.Ajax.isCallInProgress(transId) : !! this.transId;            \r
308         },\r
309     \r
310         <div id="method-Ext.data.Connection-abort"></div>/**\r
311          * Aborts any outstanding request.\r
312          * @param {Number} transactionId (Optional) defaults to the last transaction\r
313          */\r
314         abort : function(transId){\r
315             if(transId || this.isLoading()){\r
316                 Ext.lib.Ajax.abort(transId || this.transId);\r
317             }\r
318         },\r
319 \r
320         // private\r
321         handleResponse : function(response){\r
322             this.transId = false;\r
323             var options = response.argument.options;\r
324             response.argument = options ? options.argument : null;\r
325             this.fireEvent(REQUESTCOMPLETE, this, response, options);\r
326             if(options.success){\r
327                 options.success.call(options.scope, response, options);\r
328             }\r
329             if(options.callback){\r
330                 options.callback.call(options.scope, options, true, response);\r
331             }\r
332         },\r
333 \r
334         // private\r
335         handleFailure : function(response, e){\r
336             this.transId = false;\r
337             var options = response.argument.options;\r
338             response.argument = options ? options.argument : null;\r
339             this.fireEvent(REQUESTEXCEPTION, this, response, options, e);\r
340             if(options.failure){\r
341                 options.failure.call(options.scope, response, options);\r
342             }\r
343             if(options.callback){\r
344                 options.callback.call(options.scope, options, false, response);\r
345             }\r
346         },\r
347 \r
348         // private\r
349         doFormUpload : function(o, ps, url){\r
350             var id = Ext.id(),\r
351                 doc = document,\r
352                 frame = doc.createElement('iframe'),\r
353                 form = Ext.getDom(o.form),\r
354                 hiddens = [],\r
355                 hd,\r
356                 encoding = 'multipart/form-data',\r
357                 buf = {\r
358                     target: form.target,\r
359                     method: form.method,\r
360                     encoding: form.encoding,\r
361                     enctype: form.enctype,\r
362                     action: form.action\r
363                 };\r
364 \r
365             Ext.fly(frame).set({\r
366                 id: id,\r
367                 name: id,\r
368                 cls: 'x-hidden',\r
369                 src: Ext.SSL_SECURE_URL // for IE\r
370             });\r
371             doc.body.appendChild(frame);\r
372 \r
373             // This is required so that IE doesn't pop the response up in a new window.\r
374             if(Ext.isIE){\r
375                document.frames[id].name = id;\r
376             }\r
377 \r
378             Ext.fly(form).set({\r
379                 target: id,\r
380                 method: POST,\r
381                 enctype: encoding,\r
382                 encoding: encoding,\r
383                 action: url || buf.action\r
384             });\r
385 \r
386             // add dynamic params\r
387             Ext.iterate(Ext.urlDecode(ps, false), function(k, v){\r
388                 hd = doc.createElement('input');\r
389                 Ext.fly(hd).set({\r
390                     type: 'hidden',\r
391                     value: v,\r
392                     name: k\r
393                 });\r
394                 form.appendChild(hd);\r
395                 hiddens.push(hd);\r
396             });\r
397 \r
398             function cb(){\r
399                 var me = this,\r
400                     // bogus response object\r
401                     r = {responseText : '',\r
402                          responseXML : null,\r
403                          argument : o.argument},\r
404                     doc,\r
405                     firstChild;\r
406 \r
407                 try{\r
408                     doc = frame.contentWindow.document || frame.contentDocument || WINDOW.frames[id].document;\r
409                     if(doc){\r
410                         if(doc.body){\r
411                             if(/textarea/i.test((firstChild = doc.body.firstChild || {}).tagName)){ // json response wrapped in textarea\r
412                                 r.responseText = firstChild.value;\r
413                             }else{\r
414                                 r.responseText = doc.body.innerHTML;\r
415                             }\r
416                         }\r
417                         //in IE the document may still have a body even if returns XML.\r
418                         r.responseXML = doc.XMLDocument || doc;\r
419                     }\r
420                 }\r
421                 catch(e) {}\r
422 \r
423                 Ext.EventManager.removeListener(frame, LOAD, cb, me);\r
424 \r
425                 me.fireEvent(REQUESTCOMPLETE, me, r, o);\r
426 \r
427                 function runCallback(fn, scope, args){\r
428                     if(Ext.isFunction(fn)){\r
429                         fn.apply(scope, args);\r
430                     }\r
431                 }\r
432 \r
433                 runCallback(o.success, o.scope, [r, o]);\r
434                 runCallback(o.callback, o.scope, [o, true, r]);\r
435 \r
436                 if(!me.debugUploads){\r
437                     setTimeout(function(){Ext.removeNode(frame);}, 100);\r
438                 }\r
439             }\r
440 \r
441             Ext.EventManager.on(frame, LOAD, cb, this);\r
442             form.submit();\r
443 \r
444             Ext.fly(form).set(buf);\r
445             Ext.each(hiddens, function(h) {\r
446                 Ext.removeNode(h);\r
447             });\r
448         }\r
449     });\r
450 })();\r
451 \r
452 <div id="cls-Ext.Ajax"></div>/**\r
453  * @class Ext.Ajax\r
454  * @extends Ext.data.Connection\r
455  * <p>The global Ajax request class that provides a simple way to make Ajax requests\r
456  * with maximum flexibility.</p>\r
457  * <p>Since Ext.Ajax is a singleton, you can set common properties/events for it once\r
458  * and override them at the request function level only if necessary.</p>\r
459  * <p>Common <b>Properties</b> you may want to set are:<div class="mdetail-params"><ul>\r
460  * <li><b><tt>{@link #method}</tt></b><p class="sub-desc"></p></li>\r
461  * <li><b><tt>{@link #extraParams}</tt></b><p class="sub-desc"></p></li>\r
462  * <li><b><tt>{@link #url}</tt></b><p class="sub-desc"></p></li>\r
463  * </ul></div>\r
464  * <pre><code>\r
465 // Default headers to pass in every request\r
466 Ext.Ajax.defaultHeaders = {\r
467     'Powered-By': 'Ext'\r
468 };\r
469  * </code></pre> \r
470  * </p>\r
471  * <p>Common <b>Events</b> you may want to set are:<div class="mdetail-params"><ul>\r
472  * <li><b><tt>{@link Ext.data.Connection#beforerequest beforerequest}</tt></b><p class="sub-desc"></p></li>\r
473  * <li><b><tt>{@link Ext.data.Connection#requestcomplete requestcomplete}</tt></b><p class="sub-desc"></p></li>\r
474  * <li><b><tt>{@link Ext.data.Connection#requestexception requestexception}</tt></b><p class="sub-desc"></p></li>\r
475  * </ul></div>\r
476  * <pre><code>\r
477 // Example: show a spinner during all Ajax requests\r
478 Ext.Ajax.on('beforerequest', this.showSpinner, this);\r
479 Ext.Ajax.on('requestcomplete', this.hideSpinner, this);\r
480 Ext.Ajax.on('requestexception', this.hideSpinner, this);\r
481  * </code></pre> \r
482  * </p>\r
483  * <p>An example request:</p>\r
484  * <pre><code>\r
485 // Basic request\r
486 Ext.Ajax.{@link Ext.data.Connection#request request}({\r
487    url: 'foo.php',\r
488    success: someFn,\r
489    failure: otherFn,\r
490    headers: {\r
491        'my-header': 'foo'\r
492    },\r
493    params: { foo: 'bar' }\r
494 });\r
495 \r
496 // Simple ajax form submission\r
497 Ext.Ajax.{@link Ext.data.Connection#request request}({\r
498     form: 'some-form',\r
499     params: 'foo=bar'\r
500 });\r
501  * </code></pre> \r
502  * </p>\r
503  * @singleton\r
504  */\r
505 Ext.Ajax = new Ext.data.Connection({\r
506     <div id="cfg-Ext.Ajax-url"></div>/**\r
507      * @cfg {String} url @hide\r
508      */\r
509     <div id="cfg-Ext.Ajax-extraParams"></div>/**\r
510      * @cfg {Object} extraParams @hide\r
511      */\r
512     <div id="cfg-Ext.Ajax-defaultHeaders"></div>/**\r
513      * @cfg {Object} defaultHeaders @hide\r
514      */\r
515     <div id="cfg-Ext.Ajax-method"></div>/**\r
516      * @cfg {String} method (Optional) @hide\r
517      */\r
518     <div id="cfg-Ext.Ajax-timeout"></div>/**\r
519      * @cfg {Number} timeout (Optional) @hide\r
520      */\r
521     <div id="cfg-Ext.Ajax-autoAbort"></div>/**\r
522      * @cfg {Boolean} autoAbort (Optional) @hide\r
523      */\r
524 \r
525     <div id="cfg-Ext.Ajax-disableCaching"></div>/**\r
526      * @cfg {Boolean} disableCaching (Optional) @hide\r
527      */\r
528 \r
529     <div id="prop-Ext.Ajax-disableCaching"></div>/**\r
530      * @property  disableCaching\r
531      * True to add a unique cache-buster param to GET requests. (defaults to true)\r
532      * @type Boolean\r
533      */\r
534     <div id="prop-Ext.Ajax-url"></div>/**\r
535      * @property  url\r
536      * The default URL to be used for requests to the server. (defaults to undefined)\r
537      * If the server receives all requests through one URL, setting this once is easier than\r
538      * entering it on every request.\r
539      * @type String\r
540      */\r
541     <div id="prop-Ext.Ajax-extraParams"></div>/**\r
542      * @property  extraParams\r
543      * An object containing properties which are used as extra parameters to each request made\r
544      * by this object (defaults to undefined). Session information and other data that you need\r
545      * to pass with each request are commonly put here.\r
546      * @type Object\r
547      */\r
548     <div id="prop-Ext.Ajax-defaultHeaders"></div>/**\r
549      * @property  defaultHeaders\r
550      * An object containing request headers which are added to each request made by this object\r
551      * (defaults to undefined).\r
552      * @type Object\r
553      */\r
554     <div id="prop-Ext.Ajax-method"></div>/**\r
555      * @property  method\r
556      * The default HTTP method to be used for requests. Note that this is case-sensitive and\r
557      * should be all caps (defaults to undefined; if not set but params are present will use\r
558      * <tt>"POST"</tt>, otherwise will use <tt>"GET"</tt>.)\r
559      * @type String\r
560      */\r
561     <div id="prop-Ext.Ajax-timeout"></div>/**\r
562      * @property  timeout\r
563      * The timeout in milliseconds to be used for requests. (defaults to 30000)\r
564      * @type Number\r
565      */\r
566 \r
567     <div id="prop-Ext.Ajax-autoAbort"></div>/**\r
568      * @property  autoAbort\r
569      * Whether a new request should abort any pending requests. (defaults to false)\r
570      * @type Boolean\r
571      */\r
572     autoAbort : false,\r
573 \r
574     <div id="method-Ext.Ajax-serializeForm"></div>/**\r
575      * Serialize the passed form into a url encoded string\r
576      * @param {String/HTMLElement} form\r
577      * @return {String}\r
578      */\r
579     serializeForm : function(form){\r
580         return Ext.lib.Ajax.serializeForm(form);\r
581     }\r
582 });\r
583 </pre>
584 </body>
585 </html>