ajax接收Date类型的数据时会把数据转换为时间戳


复制代码 代码如下:

$("#test").click(function(e) {
$.get(
"/mgr/datacleaning/test",
function(data) {
console.log(data + " from $.get()");
}
);

var xhr = new XMLHttpRequest();
xhr.open("GET", "/mgr/datacleaning/test");
xhr.onreadystatechange= function(e) {
if (xhr.readyState == 4 && xhr.status == 200) {
console.log(xhr.responseText + " from xhr");
}
};
xhr.send(null);
});

复制代码 代码如下:

@ResponseBody
@RequestMapping(value="/test")
public Date test() {
return new Date();
}

控制台输出:

1400032471285 from $.get()
1400032471294 from xhr

By the way:

$.get()的请求头只比xhr的请求头多了一个:
X-Requested-With:
XMLHttpRequest


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3