您的当前位置:首页正文

后端用Json传值给前端及前端接收的案例

2024-11-21 来源:个人技术集锦

后端代码:

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;
      		}
	}); 
显示全文