Ext. Data. connection should be said to provide the most concise asynchronous call function with the background
The instance is as follows:
The first is the content of the ASPX page (excluding the head and JS file references)
View plaincopy to clipboardprint?
<Body>
<Div id = "form1"> </div>
</Body>
<Body>
<Div id = "form1"> </div>
</Body>
The content of extjs is written in the jsdataconnection. js file.
The content is as follows:
View plaincopy to clipboardprint?
Ext. onready (function (){
VaR form1 = new Ext. Form. formpanel ({
Width: 350,
Frame: True,
Renderto: "form1 ",
Labelwidth: 80,
Title: "form1 ",
Bodystyle: "padding: 5 p x 5 p x 0 ",
Defaults: {width: 150, xtype: "textfield "},
Items :[
{
Fieldlabel: "ID ",
ID: "ID ",
Anchor: "90%"
},
{
Fieldlabel: "name ",
ID: "name ",
Anchor: "90%"
}
],
Buttons :[
{Text: "Confirm", Handler: function () {doupdate ();}}
]
});
// Create a connection
VaR conn = new Ext. Data. Connection ({
Autoabort: false,
Defaultheaders :{
Referer: 'http: // localhost: 8080'
// Here defaultheaders can be left unspecified
},
Disablecaching: false,
Extraparams :{
Params: 'update'
},
Method: 'post ',
Timeout: 300,
URL: 'handler. ashx' // if this parameter is not specified, the current page is accessed by default.
});
/*
Where
① Autoabort: whether the request is automatically disconnected (default value: false ).
② Disablecaching: if it is set to true, a unique cache-buster parameter will be added to obtain the request (the default value is true ).
③ Extraparams: these attributes are used as external parameters in each request initiated by the connection.
④ Timeout: Connection timeout
⑤ Method: the default HTTP Method Used in the request. [Post] [get]
6. url: the requested webpage address. It is best to use the ashx page file for the URL,
If aspx is used, all page elements should be cleared; otherwise, the content received by the foreground may be faulty.
*/
Function doupdate (){
// After creating a Conn, you can call the request () function to send a request and process the returned result, as shown in the following code.
Conn. Request ({
Success: function (response ){
Ext. msg. Alert ('info', response. responsetext );
// Response. responsetext indicates the returned information.
},
Failure: function (){
Ext. msg. Alert ('warn', 'failed ');
}
});
}
// Success: method to be executed after successful execution (response is returned for the parameter)
// Failure: method to be executed upon failure
});
Ext. onready (function (){
VaR form1 = new Ext. Form. formpanel ({
Width: 350,
Frame: True,
Renderto: "form1 ",
Labelwidth: 80,
Title: "form1 ",
Bodystyle: "padding: 5 p x 5 p x 0 ",
Defaults: {width: 150, xtype: "textfield "},
Items :[
{
Fieldlabel: "ID ",
ID: "ID ",
Anchor: "90%"
},
{
Fieldlabel: "name ",
ID: "name ",
Anchor: "90%"
}
],
Buttons :[
{Text: "Confirm", Handler: function () {doupdate ();}}
]
});
// Create a connection
VaR conn = new Ext. Data. Connection ({
Autoabort: false,
Defaultheaders :{
Referer: 'http: // localhost: 8080'
// Here defaultheaders can be left unspecified
},
Disablecaching: false,
Extraparams :{
Params: 'update'
},
Method: 'post ',
Timeout: 300,
URL: 'handler. ashx' // if this parameter is not specified, the current page is accessed by default.
});
/*
Where
① Autoabort: whether the request is automatically disconnected (default value: false ).
② Disablecaching: if it is set to true, a unique cache-buster parameter will be added to obtain the request (the default value is true ).
③ Extraparams: these attributes are used as external parameters in each request initiated by the connection.
④ Timeout: Connection timeout
⑤ Method: the default HTTP Method Used in the request. [Post] [get]
6. url: the requested webpage address. It is best to use the ashx page file for the URL,
If aspx is used, all page elements should be cleared; otherwise, the content received by the foreground may be faulty.
*/
Function doupdate (){
// After creating a Conn, you can call the request () function to send a request and process the returned result, as shown in the following code.
Conn. Request ({
Success: function (response ){
Ext. msg. Alert ('info', response. responsetext );
// Response. responsetext indicates the returned information.
},
Failure: function (){
Ext. msg. Alert ('warn', 'failed ');
}
});
}
// Success: method to be executed after successful execution (response is returned for the parameter)
// Failure: method to be executed upon failure
});
The content of handler. ashx is as follows:
(I have not made any changes to the new ashx file except adding a comment)
View plaincopy to clipboardprint?
<% @ Webhandler Language = "C #" class = "handler" %>
Using system;
Using system. Web;
Public class handler: ihttphandler {
Public void processrequest (httpcontext context ){
Context. response. contenttype = "text/plain ";
// Returns the string Hello world.
Context. response. Write ("Hello World ");
}
Public bool isreusable {
Get {
Return false;
}
}
}
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/gishero/archive/2010/01/05/5133922.aspx