Ajax的xmlhttp.responseText接收问题
来源:2-7 利用Ajax实现新闻列表
那条时光流过的小巷
2019-02-27 10:00:05
在servlet中传递出去的是json对象:
String json = JSON.toJSONString(list);
response.setContentType("text/html;charset=UTF-8");
response.getWriter().println(json);而为什么在html页面中用Ajax的xmlhttp.responseText接收过来是字符串呢?
var text = xmlhttp.responseText;
为什么不能直接接收JSON?原理是什么?
1回答
同学你好,在servlet页面,是将json序列化转换为字符串。其返回值是String字符串类型的,如:

所以在html页面接受的也是字符串String类型。
如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~
相似问题