Ext. Data. Connection example

Source: Internet
Author: User

Ext. data. connection is for Ext. lib. ajax encapsulation, which provides a general method for configuring and using Ajax. It internally uses Ext. lib. ajax implementation and background asynchronous call. Compared with the underlying Ext. Lib. Ajax, ext. Data. Connection provides a simpler configuration method and makes it easier to use.

Ext. data. connection is mainly used in ext. data. httpproxy and ext. data. the scripttagproxy executes the task of interacting with the background. It obtains data from the specified URL and delivers the data returned by the background to httpproxy or scripttagproxy for processing. Ext. data. the usage of connection is as follows:CodeList


VaR conn = new Ext. Data. Connection ({

Autoabort: false,

Defaultheaders :{

Referer: 'http: // localhost: 8080 /'

},

Disablecaching: false,

Extraparams :{

Name: 'name'

},

Method: 'get ',

Timeout: 300,

URL: '01-01.txt'
});

 

Before using Ext. Data. Connection, you must create a new Ext. Connection instance as above. We can configure the corresponding parameters in the constructor, for example, autoabort indicates whether the link is automatically disconnected, the default-headers parameter indicates the default header information of the request, the disablecaching parameter indicates whether the request will disable caching, And the extraparams parameter indicates the request's additional parameters and the method parameter. the request method and timeout parameters indicate the connection timeout time, And the URL parameter indicates the requested URL.

After creating a Conn, you can call the request () function to send a request and process the returned result. The code below is as follows: 

In the request () function, you can set two callback functions, success and failure, to be called when the request succeeds and the request fails. When the request is successful, the success function parameter is the information returned by the background.

Let's take a look at other parameters in the Request function.

QURL: String: Request URL.

Q Params: Object/string/function: parameters passed by the request.

Q method: String: Request Method, usually get or post.

Q callback: function: the callback function after the request is complete. It will be executed whether it is successful or failed.

Q success: function: the callback function when the request is successful.

Q failure: function: the callback function when the request fails.

Q scope: object: The scope of the callback function.

Q form: Object/string: bound form.

Q isupload: Boolean: whether to upload files.

Q headers: object: request header information.

QXmldata:Object: XML Document Object. You can add parameters to a URL to initiate a request.

Q disablecaching: Boolean: whether to disable caching. The default value is disabled.

Ext. Data. Connection also provides the abort ([number transactionid]) function. When multiple requests occur at the same time, one of the requests is discarded Based on the specified transaction ID. If the transaction ID is not specified, the last request is discarded. The usage of the isloading ([number transactionid]) function is similar to that of abort (). You can determine whether the corresponding request is completed based on the transaction ID. If no transaction ID is specified, it determines whether the last request is complete.

Conn. Request ({

Success: function (response ){

Ext. msg. Alert ('info', response. responsetext );

},

Failure: function (){

Ext. msg. Alert ('warn', 'failed ');

}

});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.