欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery Ajax請求后臺數(shù)據(jù)并在前臺接收

 更新時(shí)間:2016年12月10日 10:00:45   作者:LexNg  
這篇文章主要介紹了jQuery Ajax請求后臺數(shù)據(jù)并在前臺接收的相關(guān)資料,需要的朋友可以參考下

1、前臺使用jQuery ajax請求

$.ajax({
url: "r_getRolePer.action",
dataType:'json', 
data: {userId:"1"}, //請求的附加參數(shù),用json對象
method:'POST',
success: function(data){
$.messager.alert('消息',data.add,'');
//這里使用的時(shí)easyui的格式
},
});

2、在action里面使用response.getWriter()的PrintWriter對象將數(shù)據(jù)打印到前臺

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();

注意這里將permision對象打印到前臺是一個(gè)json字符串,在第一步的ajax請求的success返回的data取到的就是這個(gè)permision對象,所以使用data.add就個(gè)可以取到j(luò)son對象的值,如果后臺打印到前臺的數(shù)據(jù)不是json的話而是list對象使用data[0]這樣也可以取到,但是推薦son傳遞。

以上所述是小編給大家介紹的jQuery Ajax請求后臺數(shù)據(jù)并在前臺接收,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時(shí)回復(fù)大家的!

相關(guān)文章

最新評論