Extjs learning experience (2)

Source: Internet
Author: User

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
?
  1. 1ext. Ajax. Request ({
  2. 2 URL: 'register. aspx'
    ,
  3. 3 Params :{
  4. 4 rows: 'login'
    ,
  5. 5 loginemail: Ext. Get ('loginemail'
    ). Dom. value,
  6. 6 loginpwd: Ext. Get ('loginpwd'
    ). Dom. Value
  7. 7 },
  8. 8 success: Function
    (Response, options ){
  9. 9 VaR
    Responsearray = ext. util. JSON. Decode (response. responsetext );
  10. 10 if
    (Responsearray. Success =
    'True'
    ){
  11. 11 cookies. Set ('allcard _ username'
    , Responsearray. User );
  12. 12 Ext. msg. Alert ('info'
    ,
    'You have successfully logged on! '
    , Islogin );
  13. 13}
  14. 14 else
    {
  15. 15 Ext. msg. Alert ('failed'
    ,
    'Logon failed. Please confirm that your account password is correct! '
    );
  16. 16}
  17. 17}
  18. 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
?
  1. String result =
    "{Success: True, user: 'winson '}"
    ;
  2. Response. Write (result );
  3. Response. End ();
string result = "{success:true,user:'winson'}";Response.Write(result);Response.End();

PHP writing

View plain
Copy to clipboard
Print
?
  1. $ Result =
    "{Success: True, user: 'winson '}"
    ;
  2. Print $ result;
  3. 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/

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.