📄 connection.js
字号:
* <li><b>failure</b> : Function (Optional)<div class="sub-desc">The function * to be called upon failure of the request. The callback is passed the * following parameters:<ul> * <li><b>response</b> : Object<div class="sub-desc">The XMLHttpRequest object containing the response data.</div></li> * <li><b>options</b> : Object<div class="sub-desc">The parameter to the request call.</div></li> * </ul></div></li> * <li><b>scope</b> : Object (Optional)<div class="sub-desc">The scope in * which to execute the callbacks: The "this" object for the callback function. If the <tt>url</tt>, or <tt>params</tt> options were * specified as functions from which to draw values, then this also serves as the scope for those function calls. * Defaults to the browser window.</div></li> * <li><b>form</b> : Element/HTMLElement/String (Optional)<div class="sub-desc">The <tt><form></tt> * Element or the id of the <tt><form></tt> to pull parameters from.</div></li> * <li><a id="request-option-isUpload"></a><b>isUpload</b> : Boolean (Optional)<div class="sub-desc"><b>Only meaningful when used * with the <tt>form</tt> option</b>. * <p>True if the form object is a file upload (will be set automatically if the form was * configured with <b><tt>enctype</tt></b> "multipart/form-data").</p> * <p>File uploads are not performed using normal "Ajax" techniques, that is they are <b>not</b> * performed using XMLHttpRequests. Instead the form is submitted in the standard manner with the * DOM <tt><form></tt> element temporarily modified to have its * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer * to a dynamically generated, hidden <tt><iframe></tt> which is inserted into the document * but removed after the return data has been gathered.</p> * <p>The server response is parsed by the browser to create the document for the IFRAME. If the * server is using JSON to send the return object, then the * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">Content-Type</a> header * must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.</p> * <p>The response text is retrieved from the document, and a fake XMLHttpRequest object * is created containing a <tt>responseText</tt> property in order to conform to the * requirements of event handlers and callbacks.</p> * <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> * and some server technologies (notably JEE) may require some custom processing in order to * retrieve parameter names and parameter values from the packet content.</p> * </div></li> * <li><b>headers</b> : Object (Optional)<div class="sub-desc">Request * headers to set for the request.</div></li> * <li><b>xmlData</b> : Object (Optional)<div class="sub-desc">XML document * to use for the post. Note: This will be used instead of params for the post * data. Any params will be appended to the URL.</div></li> * <li><b>jsonData</b> : Object/String (Optional)<div class="sub-desc">JSON * data to use as the post. Note: This will be used instead of params for the post * data. Any params will be appended to the URL.</div></li> * <li><b>disableCaching</b> : Boolean (Optional)<div class="sub-desc">True * to add a unique cache-buster param to GET requests.</div></li> * </ul></p> * <p>The options object may also contain any other property which might be needed to perform * postprocessing in a callback because it is passed to callback functions.</p> * @return {Number} transactionId The id of the server transaction. This may be used * to cancel the request. */ request : function(o){ var me = this; if(me.fireEvent(BEFOREREQUEST, me, o)){ if (o.el) { if(!Ext.isEmpty(o.indicatorText)){ me.indicatorText = '<div class="loading-indicator">'+o.indicatorText+"</div>"; } if(me.indicatorText) { Ext.getDom(o.el).innerHTML = me.indicatorText; } o.success = (Ext.isFunction(o.success) ? o.success : function(){}).createInterceptor(function(response) { Ext.getDom(o.el).innerHTML = response.responseText; }); } var p = o.params, url = o.url || me.url, method, cb = {success: handleResponse, failure: handleFailure, scope: me, argument: {options: o}, timeout : o.timeout || me.timeout }, form, serForm; if (Ext.isFunction(p)) { p = p.call(o.scope||WINDOW, o); } p = Ext.urlEncode(me.extraParams, typeof p == 'object' ? Ext.urlEncode(p) : p); if (Ext.isFunction(url)) { url = url.call(o.scope || WINDOW, o); } if(form = Ext.getDom(o.form)){ url = url || form.action; if(o.isUpload || /multipart\/form-data/i.test(form.getAttribute("enctype"))) { return doFormUpload.call(me, o, p, url); } serForm = Ext.lib.Ajax.serializeForm(form); p = p ? (p + '&' + serForm) : serForm; } method = o.method || me.method || ((p || o.xmlData || o.jsonData) ? POST : GET); if(method == GET && (me.disableCaching || o.disableCaching !== false)) {// || o.disableCaching === true){ var dcp = o.disableCachingParam || me.disableCachingParam; url += (url.indexOf('?') != -1 ? '&' : '?') + dcp + '=' + (new Date().getTime()); } o.headers = Ext.apply(o.headers || {}, me.defaultHeaders || {}); if(o.autoAbort === true || me.autoAbort) { me.abort(); } if((method == GET || o.xmlData || o.jsonData) && p){ url += (/\?/.test(url) ? '&' : '?') + p; p = ''; } return me.transId = Ext.lib.Ajax.request(method, url, cb, p, o); }else{ return o.callback ? o.callback.apply(o.scope, [o,UNDEFINED,UNDEFINED]) : null; } }, /** * Determine whether this object has a request outstanding. * @param {Number} transactionId (Optional) defaults to the last transaction * @return {Boolean} True if there is an outstanding request. */ isLoading : function(transId){ return transId ? Ext.lib.Ajax.isCallInProgress(transId) : !! this.transId; }, /** * Aborts any outstanding request. * @param {Number} transactionId (Optional) defaults to the last transaction */ abort : function(transId){ if(transId || this.isLoading()){ Ext.lib.Ajax.abort(transId || this.transId); } } });})();/** * @class Ext.Ajax * @extends Ext.data.Connection * <p>The global Ajax request class that provides a simple way to make Ajax requests * with maximum flexibility.</p> * <p>Since Ext.Ajax is a singleton, you can set common properties/events for it once * and override them at the request function level only if necessary.</p> * <p>Common <b>Properties</b> you may want to set are:<div class="mdetail-params"><ul> * <li><b><tt>{@link #method}</tt></b><p class="sub-desc"></p></li> * <li><b><tt>{@link #extraParams}</tt></b><p class="sub-desc"></p></li> * <li><b><tt>{@link #url}</tt></b><p class="sub-desc"></p></li> * </ul></div> * <pre><code>// Default headers to pass in every requestExt.Ajax.defaultHeaders = { 'Powered-By': 'Ext'}; * </code></pre> * </p> * <p>Common <b>Events</b> you may want to set are:<div class="mdetail-params"><ul> * <li><b><tt>{@link Ext.data.Connection#beforerequest beforerequest}</tt></b><p class="sub-desc"></p></li> * <li><b><tt>{@link Ext.data.Connection#requestcomplete requestcomplete}</tt></b><p class="sub-desc"></p></li> * <li><b><tt>{@link Ext.data.Connection#requestexception requestexception}</tt></b><p class="sub-desc"></p></li> * </ul></div> * <pre><code>// Example: show a spinner during all Ajax requestsExt.Ajax.on('beforerequest', this.showSpinner, this);Ext.Ajax.on('requestcomplete', this.hideSpinner, this);Ext.Ajax.on('requestexception', this.hideSpinner, this); * </code></pre> * </p> * <p>An example request:</p> * <pre><code>// Basic requestExt.Ajax.{@link Ext.data.Connection#request request}({ url: 'foo.php', success: someFn, failure: otherFn, headers: { 'my-header': 'foo' }, params: { foo: 'bar' }});// Simple ajax form submissionExt.Ajax.{@link Ext.data.Connection#request request}({ form: 'some-form', params: 'foo=bar'}); * </code></pre> * </p> * @singleton */Ext.Ajax = new Ext.data.Connection({ /** * @cfg {String} url @hide */ /** * @cfg {Object} extraParams @hide */ /** * @cfg {Object} defaultHeaders @hide */ /** * @cfg {String} method (Optional) @hide */ /** * @cfg {Number} timeout (Optional) @hide */ /** * @cfg {Boolean} autoAbort (Optional) @hide */ /** * @cfg {Boolean} disableCaching (Optional) @hide */ /** * @property disableCaching * True to add a unique cache-buster param to GET requests. (defaults to true) * @type Boolean */ /** * @property url * The default URL to be used for requests to the server. (defaults to undefined) * If the server receives all requests through one URL, setting this once is easier than * entering it on every request. * @type String */ /** * @property extraParams * An object containing properties which are used as extra parameters to each request made * by this object (defaults to undefined). Session information and other data that you need * to pass with each request are commonly put here. * @type Object */ /** * @property defaultHeaders * An object containing request headers which are added to each request made by this object * (defaults to undefined). * @type Object */ /** * @property method * The default HTTP method to be used for requests. Note that this is case-sensitive and * should be all caps (defaults to undefined; if not set but params are present will use * <tt>"POST"</tt>, otherwise will use <tt>"GET"</tt>.) * @type String */ /** * @property timeout * The timeout in milliseconds to be used for requests. (defaults to 30000) * @type Number */ /** * @property autoAbort * Whether a new request should abort any pending requests. (defaults to false) * @type Boolean */ autoAbort : false, /** * Serialize the passed form into a url encoded string * @param {String/HTMLElement} form * @return {String} */ serializeForm : function(form){ return Ext.lib.Ajax.serializeForm(form); }});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -