后端代码:
StringBuffer stringBuffer = new StringBuffer("test123");
JSONObject jo = new JSONObject();
jo.put("content", stringBuffer.toString());
try {
response.setContentType("text/json");
response.setCharacterEncoding("utf-8");
response.getWriter().print(jo);
} catch (IOException e) {
e.printStackTrace();
}
前端ajax接收:
$.ajax({
type:"post",
async:false,
url:"DelJITASNTxt.do?id="+str,
dataType:"json",
success: function (data) {
var content = data.content;
}
});