cisum
// 方案2: 回调函数


// function getFile( callback ){

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

//     // 2: 打开通道
//     xhr.open( \'get\', \'test.txt\', true );

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

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

//             callback( xhr.responseText );
//         }
//     }
// }



var btn = document.querySelector( \'.btn\' );
btn.onclick = function(){

    ajax( \'test.txt\', process );        
}

function process( data ){
    alert( data );
}

 

分类:

技术点:

相关文章:

  • 2021-12-20
  • 2021-12-20
  • 2021-09-12
  • 2021-10-19
  • 2021-09-01
  • 2021-12-10
  • 2021-12-10
猜你喜欢
  • 2021-12-20
  • 2021-08-04
  • 2021-10-26
  • 2021-12-10
相关资源
相似解决方案