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