复制代码 代码如下:
$("#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