JQuery AJAX requests background data and receives _jquery in the foreground

Source: Internet
Author: User
Tags json

1, the front desk using jquery ajax request

$.ajax ({
URL: "R_getroleper.action",
dataType: ' JSON ', 
data: {userId: "1"},//Request additional parameters, with JSON object
Method: ' POST ',
success:function (data) {
$.messager.alert (' message ', Data.add, ');
This is used in the Easyui format
},}
);

2, the action inside the use of Response.getwriter () PrintWriter object to print data to the foreground

Public PrintWriter out () throws ioexception{
HttpServletResponse response=servletactioncontext.getresponse (); 
    Response.setcontenttype ("text/html"); 
    Response.setcontenttype ("Text/plain; Charset=utf-8 ");
    PrintWriter out= response.getwriter ();
    return out;
}
jsonobject permision = new Jsonobject ();
Permision.put ("Add", 0);
Permision.put ("delete", 0);
Permision.put ("Update", 0);
Out (). Print (permision.tostring ());
Out (). Flush ();
Out (). Close ();

Note that the Permision object is printed to the foreground is a JSON string, and in the first step of the AJAX request the success returns the data to the Permision object, So using Data.add is a value that you can get to the JSON object, if the data in the background is not JSON, but the list object uses data[0] so you can get it, but it's recommended son delivery.

The above is a small set to introduce the jquery Ajax request background data and reception in the foreground, I hope to help you, if you have any questions welcome to my message, small series will promptly reply to everyone!

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.