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!