自己踏过的坑,终于搞懂了:
$.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互转的全部内容,更多相关$内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复