Ext. Ajax get the return value (parameter)

Source: Internet
Author: User

 

 
Ext. ajax. request ({URL: 'http: // localhost: 8080/MyApp/exthandler, jsondata: ext. util. JSON. encode (Info), Params: {Action: 'up'}, success: function (resp, opts) {var resptext = ext. util. JSON. decode (resp. responsetext); Ext. MSG. alert ('hprompt ', resptext.info) ;}, failure: function (resp, opts) {var resptext = ext. util. JSON. decode (resp. responsetext); Ext. MSG. alert ('error', resptext. error );}});

CodeThe URL parameter in specifies a java servlet that submits JSON-format data to the servlet for processing through the jsondata parameter. You can also submit other parameters, which are defined in the Params parameter; then Ext. ajax calls the corresponding success or failure callback function for processing;

How can I get the data defined in the jsondata parameter in Servlet? See the following code:

Stringbuffer JSON = new stringbuffer (); string line = NULL; try {bufferedreader reader = Req. getreader (); While (line = reader. Readline ())! = NULL) {// read JSON. append (line);} catch (exception e ){}

The server successfully processes the data and sets the returned information:

 
RSP. setcontenttype ("text/JSON; charset = UTF-8"); RSP. getwriter (). write ("{success: false, error: 'failed to update information because:" + err + "'}"); RSP. setstatus (httpservletresponse. SC _expectation_failed); // set the failure identifier // The failure callback function will call and execute and output resptext. error Information

Http://hi.baidu.com/jsjok/blog/item/5025573781c0300b90ef39e6.html

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.