ajax三步骤

来源:互联网 发布:点点客小店有软件吗 编辑:程序博客网 时间:2024/04/29 13:11
/**
 * Created by Administrator on 2016/12/19.
 */
//type:类型:GET  OR  POST
//address:路径;   返回值为获取的json对象
function getJson(type,address,Good){
    var http;
    if(window.XMLHttpRequest){
        http = new XMLHttpRequest();
    }else{
        http = new ActiveXObject("Microsoft.XMLHTTP");
    }
    //处理数据
    http.onreadystatechange function (){
        if(http.readyState == && http.status == 200){
            var JsonStr = http.responseText;
            var json = JSON.parse(JsonStr);
            //处理数据
            Good(json);
        }
    };
    //发送请求
    http.open(type,address,true);
    http.setRequestHeader("content-type","application/x-www-form-urlencoded");
    http.send();
}
0 0