JQuery Ajax requests background data and receives it at the front end. jqueryajax

Source: Internet
Author: User

JQuery Ajax requests background data and receives it at the front end. jqueryajax

1. jQuery ajax request at the front end

$. Ajax ({url: "r_getRolePer.action", dataType: 'json', data: {userId: "1"}, // additional request parameters, using the json object method: 'post', success: function (data) {$. messager. alert ('message', data. add, ''); // easyui format used here },});

2. Use the PrintWriter object of response. getWriter () in the action to print the 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 printing the permision object to the foreground is a json string. In the first step of ajax request, the data returned by success is the permision object, so data is used. add can get the value of the json object. If the data printed to the foreground in the background is not json, the value of the list object can also be obtained using data [0], but son is recommended to pass it.

The above is a small series of jQuery Ajax requests background data and receives it at the front end. I hope it will help you. If you have any questions, please leave a message, the editor will reply to you in time!

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.