In fact, ext. Ajax is not difficult to use, but I have never been clear about how to obtain the returned value. It has been depressing for a while. The following is a simple example.
View plain
Copy to clipboard
Print
?
- 1ext. Ajax. Request ({
- 2 URL: 'register. aspx'
,
- 3 Params :{
- 4 rows: 'login'
,
- 5 loginemail: Ext. Get ('loginemail'
). Dom. value,
- 6 loginpwd: Ext. Get ('loginpwd'
). Dom. Value
- 7 },
- 8 success: Function
(Response, options ){
- 9 VaR
Responsearray = ext. util. JSON. Decode (response. responsetext );
- 10 if
(Responsearray. Success =
'True'
){
- 11 cookies. Set ('allcard _ username'
, Responsearray. User );
- 12 Ext. msg. Alert ('info'
,
'You have successfully logged on! '
, Islogin );
- 13}
- 14 else
{
- 15 Ext. msg. Alert ('failed'
,
'Logon failed. Please confirm that your account password is correct! '
);
- 16}
- 17}
- 18 });
1ext. ajax. request ({2 URL: 'register. aspx ', 3 Params: {4 rows: 'login', 5 loginemail: ext. get ('loginemail '). dom. value, 6 loginpwd: ext. get ('loginpwd '). dom. value 7}, 8 success: function (response, options) {9 var responsearray = ext. util. JSON. decode (response. responsetext); 10 if (responsearray. success = 'true') {11 cookies. set ('allcard _ username', responsearray. user); 12 Ext. MSG. alert ('info', 'you have successfully logged on! ', Islogin); 13} 14 else {15 Ext. msg. Alert ('failed', 'logon failed. Please confirm that your account and password are correct! '); 16} 17} 18 });
Code Description:
Line 2: URL parameters are the pages to be submitted
Row 3: Params is a set of parameters to be submitted, separated by commas (,).
Row 8: The function to be executed after the callback is successful.
Row 9: Get the server-side callback parameter value
Row 10: Judge and process the callback value.
The following describes how to obtain the callback parameter value. In extjs, parameters are obtained through the JSON data format. Therefore, after the server completes the processing, the callback parameter should be written as follows:
ASP. NET
View plain
Copy to clipboard
Print
?
- String result =
"{Success: True, user: 'winson '}"
;
- Response. Write (result );
- Response. End ();
string result = "{success:true,user:'winson'}";Response.Write(result);Response.End();
PHP writing
View plain
Copy to clipboard
Print
?
- $ Result =
"{Success: True, user: 'winson '}"
;
- Print $ result;
- Exit ();
$result = "{success:true,user:'winson'}";print $result;exit();
The data is returned in the form of a key-value pair. When receiving the data, you can use the method of line 9th in the first code to receive the data. Because the data is in JSON format, therefore, the server can easily return multiple parameter values at the same time.
Ext. Ajax is basically used in this way. In fact, it is quite simple, but if you want to increase the loading effect during submission, it will be quite troublesome. I have not studied it in depth here.
There are more complex form applications!
This series of articles is referenced from:
Winson's blog
Http://www.cnblogs.com/winsonet/