自己踏过的坑,终于搞懂了:
$.ajax({
type: “POST”,
url: “/user/saveShuoshuo”,
data:{
nicheng:name,
content:txt,
time:nowTime
},
dataType: “json”,
// success: function(data){}
//error:window.location.reload()
})
等价于:
var xmlhttp = new XMLHttpRequest();
xmlhttp.open(“POST”, “/user/saveShuoshuo”, true);
//?nicheng=" + name + “&content=” + txt + “&time=” + nowTime
var fd = new FormData();
fd.append(“nicheng”, name);
fd.append(“content”, txt);
fd.append(“time”, nowTime);
xmlhttp.send(fd);
//xmlhttp.onreadystatechange = function(data){
//若响应完成且请求成功
if(xmlhttp.readyState === 4 && xmlhttp.status === 200){
//do something, e.g. request.responseText
}
$.AJAX与xmlhttprequest互转
最新推荐文章于 2023-03-18 17:27:07 发布