时间:2021-07-01 10:21:17 帮助过:47人阅读
代码如下:
$("#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