用 Microsoft Ajax Library 异步获取页面并显示2跨域读取RSS并处理

取个RSS并显示(在取的时候处理为HTML)
<! 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 (){ // 完成载入时的函数
     var  b = new  String(xhe.get_responseData());
    b
= b.replace( /< / ? xml /w +>/ g, "" ); // 用正则替换一番
    b = b.replace( /< rss/w +>/ g, " <div> " );
    
/**/ b = b.replace( / rss >/ g, " div> " );
    b
= b.replace( / channel >/ g, " ul> " );
    b
= b.replace( / item >/ g, " li> " );
    b
= b.replace( / description >/ g, " div> " );
    b
= b.replace( /< description ><! /[CDATA/[ / g, " <div> " );
    b
= b.replace( / title >/ g, " h3> " );
    b
= b.replace( / /]/] >/ g, "" );
    b
= b.replace( /< link >/ g, " <a href= " );
    b
= b.replace( /< / / link >< dc:creator >/ , " > " );
    b
= b.replace( /< / / dc:creator >/ g, " </a> " );
    b
= b.replace( /< author > /w +< / / author >/ g, "" );
    
// alert(b);
    $get( " as " ).innerHTML = b;
    });
    xhe.executeRequest();
// 执行
}
</ script >
<!-- 更改Click 的参数即可访问本地 -->
< href ="javascript:click('http://www.cnblogs.com/chsword/category/86648.html/rss')" > Get My Blog Rss </ a >
< div  id ="as" > init </ div >
</ body >
</ html >
 

你可能感兴趣的:(用 Microsoft Ajax Library 异步获取页面并显示2跨域读取RSS并处理)