jqurey ajax 后台传值给前端代码怎么写
1个回答
2017-09-26
展开全部
$.ajax({
type: "POST",
url: "",//后台路径
data: {},//参数
//async: true,
dataType: "json",
success: function (response) {
console,log(response);
},
error: function () {
}
});
//后台代码
@RequestMapping(params = "method=removeBinding")
public @ResponseBody
String removeBinding(HttpServletRequest request, HttpServletResponse response) {
try {
JSONObject obj = new JSONObject();
obj.put("errcode", "1");
return obj.toString();
} catch (Exception ex) {
}
}
用json进行传值,后台put()给一个变量errcode值为1,前台ajax里的success可以直接用console.log()打出来
type: "POST",
url: "",//后台路径
data: {},//参数
//async: true,
dataType: "json",
success: function (response) {
console,log(response);
},
error: function () {
}
});
//后台代码
@RequestMapping(params = "method=removeBinding")
public @ResponseBody
String removeBinding(HttpServletRequest request, HttpServletResponse response) {
try {
JSONObject obj = new JSONObject();
obj.put("errcode", "1");
return obj.toString();
} catch (Exception ex) {
}
}
用json进行传值,后台put()给一个变量errcode值为1,前台ajax里的success可以直接用console.log()打出来
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询