AJAX

来源:互联网 发布:python str.format 编辑:程序博客网 时间:2024/06/01 10:50
    // for IE8+     function myGet() {        var xhr =new XMLHttpRequest();        var url = 'get.php?k1=v1&k2=v2&k3=v3';        xhr.open('get',url,true);        xhr.onreadystatechange=function () {            if (xhr.readyState===4) {                if (xhr.status===200) {                    console.log(xhr.responseText);                }else{                    console.log('ajax error');                }            }        }        xhr.send(null);    }    function myPost() {        var xhr = new XMLHttpRequest();        var url = "post.php";        var data='k1=v1&k2=v2';        xhr.open('post',url,true);        xhr.onreadystatechange=function () {            if (xhr.readyState==4) {                if (xhr.status==200) {                    console.log(xhr.responseText);                }else{                    console.log('xhr error check please');                }            }        }        xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');        xhr.send(data);    }
原创粉丝点击