ajax基本使用

// 1: 创建ajax对象 XMLHttpRequest
var xhr = new XMLHttpRequest();


// 2: 打开通道
// 请求方式
// 请求地址
// 是否异步 默认true, false
xhr.open( 'get', 'test.txt', true );



// 3: 发送请求
xhr.send();


// 4:监听通道
xhr.onreadystatechange = function( res ){
    if( xhr.status === 200 && xhr.readyState === 4 ){

    }
    else{
        dialog.error( '数据请求失败' );
    }



    // if( xhr.status === 200 && xhr.readyState === 4  ){
    //     // console.log( xhr.responseText );
    // }
}

 

posted @ 2017-12-06 15:43  Sunsin  阅读(300)  评论(0编辑  收藏  举报