温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

原生Ajax总结

发布时间:2020-06-05 20:38:41 来源:网络 阅读:251 作者:sshpp 栏目:网络安全

HTTP协议

传统的请求和Ajax请求
原生Ajax总结

Ajax定义

Asynchronous JavaScript and XML. Ajax异步的,JavaScript程序希望与服务器直接通信而不需要重新加载页面。

Ajax基本流程

1.创建请求对象

function requestObject(){
            if(window.XMLHttpRequest){
                return new XMLHttpRequest();
            }else if{
                return new ActiveXObject('Mxsml2.XMLHTTP');
            }else{
                throw new Error("Could not create HTTP request object.");
            }
        }

2.建立请求
var request=requestObject();
request.open("GET","data.txt",true);

3.发送请求

request.send(null);

4.处理请求(XML和JSON两种格式)

request.onreadystatechange=function(){            if(request.readyState==4){                console.log(request.status+":"+request.statusText);
            }
        }


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI