js原生ajax写法

我来纠错
var xhr = new XMLHttpRequest();  // XMLHttpRequest对象用于在后台与服务器交换数据          
xhr.open('GET', 'http://www.fuzhangkeji.com/api/weixin/wxsdk.php?url='+encodeURIComponent(location.href), true);
xhr.send();
xhr.onreadystatechange = function() {
        if (xhr.readyState == 4 && xhr.status == 200 || xhr.status == 304) { // readyState == 4说明请求已完成
                var data = JSON.parse(xhr.responseText);
        }
}

//POST方式
xhr.open('POST', '/someurl/somepage', true);
//设置请求头
xhr.setRequestHeader("Content-Type", "application/json");
//传递参数
xhr.send('param1=value1¶m2=value2');

发送
热门关键词:
命令
知识类型:
标题描述:
详细解答:

提交审核您编辑的知识会经过 前端大牛 人工审核。