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