原生ajax

<script>
    var xhr;
//兼容ajax請求
    if (window.XMLHttpRequest) {
        xhr = new XMLHttpRequest();
    } else {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    var url = 'http://ccvt_test.fnying.com/api/bot_web/group_list.php?token=PNySspBA0hK9ZWn0WOhqXk2GbJVjhdCRR%2FR0fNIyU7V0%2B5xF%2BSjhwQfclpJvz3G4WoeDnjBUCPM2V6AEA2MepQ%3D%3D';
//post:請求方式;url:請求地址;true:是否異步;
    xhr.open("POST", url, true);
//post請求設置響應頭
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//添加監聽
    xhr.onreadystatechange = function (res) {
        if (xhr.status == 200 && xhr.readyState == 4) {
            console.log(xhr.responseText);
        }
    };
    xhr.send();
</script>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章