AJAX初级应用-RSS无刷新聚合器的代码与下载第1/
网络编程 2021-07-05 10:36www.168986.cn编程入门
rss.js
<!--
//控制ID
function getId(objId){
return document.getElementById(objId)
}
//链接对应数组,请注明网络推广网站推广转载自http://.rui./blog
function urlArrary(urlName){
switch(urlName){
case "clear":
return "http://.rui./blog/feed.asp"
case "a-fei":
return "http://.a-fei./blog/rss.xml"
case "ryanxia":
return "http://.ryanxia./blog/feedrss2.asp"
case "awflasher":
return "http://.awflasher./blog/feed.asp"
case "seles":
return "http://.rui./seles/feedrss2.asp"
case "wawa":
return "http://a-fei./wawa/blog/rss2.php"
case "dreammx":
return "http://.dreammx./xhyl/feed.asp"
default:
return false
}
}
//侧边栏控制,请注明自http://.rui./blog网络推广网站推广转载
function closebar(targetid,objId){
if(document.getElementById){
target = getId(targetid);
objsty = getId(objId);
if(target.style.display == "none"){
target.style.display = "";
main.style.width = "800px";
objsty.innerHTML = "关闭侧边栏"
}else{
target.style.display = "none";
main.style.width = "100%";
objsty.innerHTML = "开启侧边栏"
}
}
}
//加载变灰,注明自http://.rui./blog网络推广网站推广转载
function listen(a){
getId("prolist").className=a;
}
function btnSty(objId,objStyle)
{
getId(objId).style.display = objStyle
}
//提示窗口控制
function ifodis(){
btnSty("loadifo","none");
}
function settime(a){
setTimeout(a,1000);
}
function loadtime(){
getId("loadifo").innerHTML += "."
}
//数据入口
function ent(urlName){
window.location.hash = urlName
var frmUrl = saveState(urlName);//写入信息到ifream
var gamestart = loadrss(urlName);//AJAX数据过程
}
//XML数据绑定
var xmldoc = false;
function loadrss(urlName){
var myurl = urlArrary(urlName)
if(myurl){
listen("mainbg2");
//生成随机数,限制刷新次数
var Num=Math.floor(Math.random()100);
//定义往址参数
url = myurl+"?id="+Num;
//定义为异步传输模式
xmldoc = false;
//Mozill,Safari等浏览器时需要创建的XMLHttp类
if(window.XMLHttpRequest){
xmldoc = new XMLHttpRequest();
if(xmldoc.overrideMimeType){
xmldoc.overrideMimeType('text/xml');
}
}
//IE浏览器时创建的XMLHttp类
else if(window.ActiveXObject){
try{
xmldoc = new ActiveXObject("Msxml3.XMLHTTP");
}
catch(e){
try{
xmldoc = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e){
try{
xmldoc = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){}
}
}
}
//不能创建XMLHTTP类时返回
if(! xmldoc){
return false;
}
//调用CheckState函数
xmldoc.onreadystatechange = CheckState;
xmldoc.open('GET',url,true);
xmldoc.send(null);
}else{
getId("listnum").innerHTML = "您输入的地址错误,请重试!"
}
}
//状态检测
function CheckState(){
var response = xmldoc.responseXML.documentElement;
btnSty("loadifo","block")
//收到完整的服务器响应
if(xmldoc.readyState == 1){
getId("loadifo").innerHTML = "连接服务器"
}
else if(xmldoc.readyState == 2){
getId("loadifo").innerHTML = "开始加载数据"
}
else if(xmldoc.readyState == 3){
getId("loadifo").innerHTML = "正在加载数据"
settime(loadtime)
}
else if(xmldoc.readyState == 4){
//HTTP服务器响应值成功
if(xmldoc.status == 200){
//将服务器返回的字符串写到页面中ID为showdiv的区域
getId("loadifo").innerHTML = "加载完成"
settime(ifodis)
num(response)
}
else{
getId("loadifo").innerHTML = "错误"+xmldoc.status+"点这里刷新";
}
}
}
//检查数据合法性
function trydata(nodeName,nodeName2){
try{
var nodeV = nodeName.firstChild.nodeValue;
}catch(e){
try{
var nodeV = nodeName2.firstChild.nodeValue;
}catch(e){
var nodeV = "没有可用信息"
}
}
return nodeV;
}
//记录集总数
function num(b){
try{
var titleNode = b.selectNodes("//rss/channel/title");
var a = b.getElementsByTagName("item").length
titleV = trydata(titleNode(0));
getId("listnum").innerHTML = "共有"+a+"篇文章 来源于"+titleV;
setlist(a,b);
}catch(e){}
}
if (.location != self.location).location=self.location;
//节目列表显示
//定义接收指向各个元素的节点信息的变量
var titleNode,linkNode,categoryNameNode,authorNode,pubDateNode,descriptionNode
//定义接收元素值的变量
var titleV,linkV,categoryNameV,authorV,pubDateV,descriptionV
//分类聚合
function setlist(a,b)
{
var prograNode = b.getElementsByTagName("item");
var adminlinkNode = b.selectNodes("//rss/channel/link");
var titleNode = b.selectNodes("//rss/channel/item/title");
var linkNode = b.selectNodes("//rss/channel/item/link");
var categoryNode = b.selectNodes("//rss/channel/item/category");
var authorNode = b.selectNodes("//rss/channel/item/author");
var pubDateNode = b.selectNodes("//rss/channel/item/pubDate");
var descriptionNode = b.selectNodes("//rss/channel/item/description");
var category2sNode = b.selectNodes("//rss/channel/item/dc:subject");
var author2sNode = b.selectNodes("//rss/channel/item/dc:creator");
var pubDate2sNode = b.selectNodes("//rss/channel/item/dc:date");
var listchar=""
//使用for循环,产生列表信息
for (i=0; i<a; i++)
{
titleV = trydata(titleNode(i))
linkV = trydata(linkNode(i))
categoryV = trydata(categoryNode(i),category2sNode(i))
authorV = trydata(authorNode(i),author2sNode(i))
pubDateV = trydata(pubDateNode(i),pubDate2sNode(i))
descriptionV = trydata(descriptionNode(i))
adminlinkV = trydata(adminlinkNode(0))
//将得到的元素值装载到产生表格的字符串中
listchar += "<h5><a href='"+linkV+"' target='_blank'>"+titleV+"</a></h5><span>发表时间"+pubDateV+"</span><div class='article'>"+descriptionV+"</div><div class='bottom'>文章分类"+categoryV+" <a href='"+adminlinkV+"' target='_blank'>作者"+authorV+"</a></div>";
}
//将生成的表格输出到页面的DIV元素
getId("prolist").innerHTML = listchar;
listen("mainbg")
}
//浏览器回退部分
//重写IFREAM链接,浏览器回退重点
function saveState(message) {
var hisFrm = getId("historyFrame")
hisFrm.src = "blank.html?"+message
}
//检测IFREAM
window.dhtmlHistory = {
iframeLoaded:function(newLocation){
var hash = new String(newLocation.search)
if (hash.length >= 2 && hash.charAt(0) == "?" && hash.substring(1) !=delChar()){
hash = hash.substring(1)
window.location.hash = hash;
var hisFrmdata = loadrss(hash)
}
}
}
//浏览器链接指向部分
//去除符号,请注明http://.rui./blog网络推广网站推广转载
function delChar(){
var a = window.location.hash
return a.substring(1)
}
window.onload = function(){
if(window.location.hash.length >= 2){
ent(delChar())
}
}
// -->
代码如下:
<!--
//控制ID
function getId(objId){
return document.getElementById(objId)
}
//链接对应数组,请注明网络推广网站推广转载自http://.rui./blog
function urlArrary(urlName){
switch(urlName){
case "clear":
return "http://.rui./blog/feed.asp"
case "a-fei":
return "http://.a-fei./blog/rss.xml"
case "ryanxia":
return "http://.ryanxia./blog/feedrss2.asp"
case "awflasher":
return "http://.awflasher./blog/feed.asp"
case "seles":
return "http://.rui./seles/feedrss2.asp"
case "wawa":
return "http://a-fei./wawa/blog/rss2.php"
case "dreammx":
return "http://.dreammx./xhyl/feed.asp"
default:
return false
}
}
//侧边栏控制,请注明自http://.rui./blog网络推广网站推广转载
function closebar(targetid,objId){
if(document.getElementById){
target = getId(targetid);
objsty = getId(objId);
if(target.style.display == "none"){
target.style.display = "";
main.style.width = "800px";
objsty.innerHTML = "关闭侧边栏"
}else{
target.style.display = "none";
main.style.width = "100%";
objsty.innerHTML = "开启侧边栏"
}
}
}
//加载变灰,注明自http://.rui./blog网络推广网站推广转载
function listen(a){
getId("prolist").className=a;
}
function btnSty(objId,objStyle)
{
getId(objId).style.display = objStyle
}
//提示窗口控制
function ifodis(){
btnSty("loadifo","none");
}
function settime(a){
setTimeout(a,1000);
}
function loadtime(){
getId("loadifo").innerHTML += "."
}
//数据入口
function ent(urlName){
window.location.hash = urlName
var frmUrl = saveState(urlName);//写入信息到ifream
var gamestart = loadrss(urlName);//AJAX数据过程
}
//XML数据绑定
var xmldoc = false;
function loadrss(urlName){
var myurl = urlArrary(urlName)
if(myurl){
listen("mainbg2");
//生成随机数,限制刷新次数
var Num=Math.floor(Math.random()100);
//定义往址参数
url = myurl+"?id="+Num;
//定义为异步传输模式
xmldoc = false;
//Mozill,Safari等浏览器时需要创建的XMLHttp类
if(window.XMLHttpRequest){
xmldoc = new XMLHttpRequest();
if(xmldoc.overrideMimeType){
xmldoc.overrideMimeType('text/xml');
}
}
//IE浏览器时创建的XMLHttp类
else if(window.ActiveXObject){
try{
xmldoc = new ActiveXObject("Msxml3.XMLHTTP");
}
catch(e){
try{
xmldoc = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e){
try{
xmldoc = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){}
}
}
}
//不能创建XMLHTTP类时返回
if(! xmldoc){
return false;
}
//调用CheckState函数
xmldoc.onreadystatechange = CheckState;
xmldoc.open('GET',url,true);
xmldoc.send(null);
}else{
getId("listnum").innerHTML = "您输入的地址错误,请重试!"
}
}
//状态检测
function CheckState(){
var response = xmldoc.responseXML.documentElement;
btnSty("loadifo","block")
//收到完整的服务器响应
if(xmldoc.readyState == 1){
getId("loadifo").innerHTML = "连接服务器"
}
else if(xmldoc.readyState == 2){
getId("loadifo").innerHTML = "开始加载数据"
}
else if(xmldoc.readyState == 3){
getId("loadifo").innerHTML = "正在加载数据"
settime(loadtime)
}
else if(xmldoc.readyState == 4){
//HTTP服务器响应值成功
if(xmldoc.status == 200){
//将服务器返回的字符串写到页面中ID为showdiv的区域
getId("loadifo").innerHTML = "加载完成"
settime(ifodis)
num(response)
}
else{
getId("loadifo").innerHTML = "错误"+xmldoc.status+"点这里刷新";
}
}
}
//检查数据合法性
function trydata(nodeName,nodeName2){
try{
var nodeV = nodeName.firstChild.nodeValue;
}catch(e){
try{
var nodeV = nodeName2.firstChild.nodeValue;
}catch(e){
var nodeV = "没有可用信息"
}
}
return nodeV;
}
//记录集总数
function num(b){
try{
var titleNode = b.selectNodes("//rss/channel/title");
var a = b.getElementsByTagName("item").length
titleV = trydata(titleNode(0));
getId("listnum").innerHTML = "共有"+a+"篇文章 来源于"+titleV;
setlist(a,b);
}catch(e){}
}
if (.location != self.location).location=self.location;
//节目列表显示
//定义接收指向各个元素的节点信息的变量
var titleNode,linkNode,categoryNameNode,authorNode,pubDateNode,descriptionNode
//定义接收元素值的变量
var titleV,linkV,categoryNameV,authorV,pubDateV,descriptionV
//分类聚合
function setlist(a,b)
{
var prograNode = b.getElementsByTagName("item");
var adminlinkNode = b.selectNodes("//rss/channel/link");
var titleNode = b.selectNodes("//rss/channel/item/title");
var linkNode = b.selectNodes("//rss/channel/item/link");
var categoryNode = b.selectNodes("//rss/channel/item/category");
var authorNode = b.selectNodes("//rss/channel/item/author");
var pubDateNode = b.selectNodes("//rss/channel/item/pubDate");
var descriptionNode = b.selectNodes("//rss/channel/item/description");
var category2sNode = b.selectNodes("//rss/channel/item/dc:subject");
var author2sNode = b.selectNodes("//rss/channel/item/dc:creator");
var pubDate2sNode = b.selectNodes("//rss/channel/item/dc:date");
var listchar=""
//使用for循环,产生列表信息
for (i=0; i<a; i++)
{
titleV = trydata(titleNode(i))
linkV = trydata(linkNode(i))
categoryV = trydata(categoryNode(i),category2sNode(i))
authorV = trydata(authorNode(i),author2sNode(i))
pubDateV = trydata(pubDateNode(i),pubDate2sNode(i))
descriptionV = trydata(descriptionNode(i))
adminlinkV = trydata(adminlinkNode(0))
//将得到的元素值装载到产生表格的字符串中
listchar += "<h5><a href='"+linkV+"' target='_blank'>"+titleV+"</a></h5><span>发表时间"+pubDateV+"</span><div class='article'>"+descriptionV+"</div><div class='bottom'>文章分类"+categoryV+" <a href='"+adminlinkV+"' target='_blank'>作者"+authorV+"</a></div>";
}
//将生成的表格输出到页面的DIV元素
getId("prolist").innerHTML = listchar;
listen("mainbg")
}
//浏览器回退部分
//重写IFREAM链接,浏览器回退重点
function saveState(message) {
var hisFrm = getId("historyFrame")
hisFrm.src = "blank.html?"+message
}
//检测IFREAM
window.dhtmlHistory = {
iframeLoaded:function(newLocation){
var hash = new String(newLocation.search)
if (hash.length >= 2 && hash.charAt(0) == "?" && hash.substring(1) !=delChar()){
hash = hash.substring(1)
window.location.hash = hash;
var hisFrmdata = loadrss(hash)
}
}
}
//浏览器链接指向部分
//去除符号,请注明http://.rui./blog网络推广网站推广转载
function delChar(){
var a = window.location.hash
return a.substring(1)
}
window.onload = function(){
if(window.location.hash.length >= 2){
ent(delChar())
}
}
// -->
1
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程