Ajax Package Test notes for Ext.ajax in EXTJS4 (1/3)

Source: Internet
Author: User

This article mainly introduces several ExtJS commonly used in the JS syntax extension support, including Ajax encapsulation, function event operation encapsulation, as well as the extension of the commonly used functions. Ajax server-Side interactive operations are committed to. NET MVC. Subsequent server-side interactions are implemented this way.

First, the Ajax:Ext.Ajax.request in the ExtJS
By sending Ajax requests to the server from the client, you can call the MVC action method "directly" and pass the parameters, which can be either a normal string or a JSON object. Requests can add custom header information. Look at the following example:

1. Asynchronous request, send custom request header:
The HTML page is as follows:

[HTML]

The code is as follows Copy Code
<div class= "Content" id= "Div1" >
<div> has initiated the <span id= "Span1" style= "color:red" >0</span> requests. </div>
</div>

We first trigger an AJAX request with a button click event, and the server returns a string to the client, which, when asynchronous, adds the custom header "Userheader" to the request and gets it at the server. The following is the JS code:

The code is as follows Copy Code

[Js]
Ext.onready (function () {
New Ext.button ({
Renderto: "Div1",
Text: "Background ajax submission",
Handler:function () {
Ext.Ajax.request ({
URL: ' Ajax_func1 ',
Headers: {
' Userheader ': ' Usermsg '
},
Params: {a:10, b:20},
Method: ' Get ',
Success:function (response, options) {
Ext.MessageBox.alert (' success ', ' Get results from server end: ' + Response.responsetext ');
},
Failure:function (response, options) {
Ext.MessageBox.alert (' failed ', ' request timeout or network failure, error number: ' + response.status ');
}
});
},
ID: "BT1"
});

});


Service-side MVC accepts the requested action code:

The code is as follows Copy Code
[C #]
Public Contentresult ajax_func1 (int a, int b)
{
String userheadermsg = Convert.ToString (request.headers["Userheader"]);
Return Content ((A + B). ToString () + ", Userheader:" + userheadermsg);
}

Then we debug in Firefox: The custom request header has been added

Results

Home 1 2 3 last
Related Article

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.