用 Microsoft Ajax Library 异步获取页面并显示

这个是看了MicrosoftAjax.js的代码,从代码中推出来的。希望对大家学习ms ajax lib有帮助。

<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html  xmlns ="http://www.w3.org/1999/xhtml"   >
< head >
    
< title ></ title >
    
<!-- 将这个改成你的Ms Ajax Lib 的地址 -->
    
< script  src ="MicrosoftAjax.js"  type ="text/javascript" ></ script >
</ head >
< body >
    
< script  type ="text/javascript" >
    
function  click(_url){
    $get(
" as " ).innerHTML = " 正在载入... ... " ; // 正在载入时的信息
     var  xhe  =   new  Sys.Net.XMLHttpExecutor();
    
var  wr  =   new  Sys.Net.WebRequest();
    wr.set_url(_url);
// 设置异步访问URL 
    wr.set_httpVerb( " get " ); // 访问方式
    wr.set_executor(xhe); // 将XMLHttpExecutor与WebRequest关联
    wr.set_userContext( " my Context " ); // 设备上下文,不知是做什么用的
    wr.add_completed( function (){ // 完成载入时的函数
    $get( " as " ).innerHTML = xhe.get_responseData();
    });
    xhe.executeRequest();
// 执行
    }
    
</ script >
    
<!-- 更改Click 的参数即可访问本地 -->
< href ="javascript:click('http://www.csdn.net')" > csdn </ a >
< href ="javascript:click('http://www.cnblogs.com')" > cnblogs </ a >
< href ="javascript:click('http://www.mvking.com/bbs')" > MvKing </ a >
< div  id ="as" > init </ a >
</ body >
</ html >
 

你可能感兴趣的:(用 Microsoft Ajax Library 异步获取页面并显示)