概述
自己踏过的坑,终于搞懂了:
$.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互转的全部内容,希望文章能够帮你解决$.AJAX与xmlhttprequest互转所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复