我是靠谱客的博主 苗条路人,最近开发中收集的这篇文章主要介绍$.AJAX与xmlhttprequest互转,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

自己踏过的坑,终于搞懂了:
$.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互转所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(81)

评论列表共有 0 条评论

立即
投稿
返回
顶部