当前位置: 网学 > 编程文档 > Ajax > 正文

用Ajax读取XML格式的数据

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 13/07/11

网学网Ajax编辑为广大网友搜集整理了:用Ajax读取XML格式的数据绩等信息,祝愿广大网友取得需要的信息,参考学习

复制代码 代码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html> 
<head> 
<title>Ajax Hello World</title> 
<script type="text/javascript"> 
var xmlHttp; 

function createXMLHttpRequest(){ 
    if(window.ActiveXObject){ 
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
    else if(window.XMLHttpRequest){ 
        xmlHttp = new XMLHttpRequest(); 
    } 


function startRequest(){ 
    createXMLHttpRequest(); 
    try{ 
        xmlHttp.onreadystatechange = handleStateChange; 
        xmlHttp.open("GET", "data.xml", true); 
        xmlHttp.send(null);     
    }catch(exception){ 
        alert("您要访问的资源不存在!"); 
    } 


function handleStateChange(){     
    if(xmlHttp.readyState == 4){         
        if (xmlHttp.status == 200 || xmlHttp.status == 0){ 
            // 取得XML的DOM对象 
            var xmlDOM = xmlHttp.responseXML; 
            // 取得XML文档的根 
            var root = xmlDOM.documentElement;             
            try 
            { 
                // 取得<info>结果 
                var info = root.getElementsByTagName(''info''); 
                // 显示返回结果 
                alert("responseXML''s 

  • 上一篇资讯: Ajax loading gif generator
  • 下一篇资讯: ajax实现标签导航
  • 网学推荐

    免费论文

    原创论文

    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved 湘ICP备09003080号