新建一个.aspx文件

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="02-通过 XML HTTP 加载 XML 文件.aspx.cs"
  2. Inherits="_02_通过_XML_HTTP_加载_XML_文件" %>
  3.  
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head runat="server">
  7. <title></title>
  8. <script type="text/javascript">
  9. var xmlhttp;
  10. function loadXMLDoc(url)
  11. {
  12. xmlhttp = null;
  13. if (window.XMLHttpRequest)
  14. {// code for IE7, Firefox, Opera, etc.
  15. xmlhttp = new XMLHttpRequest();
  16. }
  17. else if (window.ActiveXObject)
  18. {// code for IE6, IE5
  19. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  20. }
  21. if (xmlhttp != null)
  22. {
  23. xmlhttp.onreadystatechange = state_Change;
  24. xmlhttp.open("GET", url, true);
  25. xmlhttp.send(null);
  26. }
  27. else
  28. {
  29. alert("Your browser does not support XMLHTTP.");
  30. }
  31. }
  32.  
  33. function state_Change()
  34. {
  35. if (xmlhttp.readyState == 4)
  36. {// 4 = "loaded"
  37. if (xmlhttp.status == 200)
  38. {// 200 = "OK"
  39. document.getElementById('A1').innerHTML = xmlhttp.status;
  40. document.getElementById('A2').innerHTML = xmlhttp.statusText;
  41. document.getElementById('A3').innerHTML = xmlhttp.responseText;
  42. }
  43. else
  44. {
  45. alert("Problem retrieving XML data:" + xmlhttp.statusText);
  46. }
  47. }
  48. }
  49. </script>
  50. </head>
  51. <body>
  52. <h2>
  53. Using the HttpRequest Object</h2>
  54. <p>
  55. <b>Status:</b> <span id="A1"></span>
  56. </p>
  57. <p>
  58. <b>Status text:</b> <span id="A2"></span>
  59. </p>
  60. <p>
  61. <b>Response:</b>
  62. <br />
  63. <span id="A3"></span>
  64. </p>
  65. <button onclick="loadXMLDoc('note.xml')">
  66. Get XML</button>
  67. </body>
  68. </html>

note.xml

  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <note>
  3. <to>George</to>
  4. <from>John</from>
  5. <heading>Reminder</heading>
  6. <body>Don't forget the meeting!</body>
  7. </note>

通过 XML HTTP 加载 XML 文件的更多相关文章

  1. Spring加载properties文件的属性的值

    要使用配置文件的值首先在spring.xml配置加载properties文件 <context:property-placeholder location="classpath:ife ...

  2. Spring加载properties文件的两种方式

    在项目中如果有些参数经常需要修改,或者后期可能需要修改,那我们最好把这些参数放到properties文件中,源代码中读取properties里面的配置,这样后期只需要改动properties文件即可, ...

  3. js便签笔记(8)——js加载XML字符串或文件

    1. 加载XML文件 方法1:ajax方式.代码如下: var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObje ...

  4. dom4j加载xml文件

    ## dom4j加载xml文件 ``` // 1. 加载xml文件 InputStream is = MyTest.class.getResourceAsStream("user.xml&q ...

  5. JavaEE互联网轻量级框架整合开发(书籍)阅读笔记(12):XML配置自动扫描包,自动加载*.properties文件

    一.XML和注解组合使用 前几篇的测试案例都是在Java类中配置,现在换一种使用方式,在XML中配置,使Spring IoC容器在启动之后自动去扫描配置的包路径,扫描加载指定路径下的propertie ...

  6. Android学习笔记_31_通过后台代码生成View对象以及动态加载XML布局文件到LinearLayout

    一.布局文件part.xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android&qu ...

  7. 通过JS加载XML文件,跨浏览器兼容

    引言 通过JS加载XML文件,跨多种浏览器兼容. 在Chrome中,没有load方法,需要特殊处理! 解决方案 部分代码 try //Internet Explorer { xmlDoc=new Ac ...

  8. 解决dom4j加载xml文件性能慢的问题

    在代码中使用: 1: DocumentHelper.parseText 2: SAXReader reader = new SAXReader(); Document extdocument = re ...

  9. Spring如何加载XSD文件(org.xml.sax.SAXParseException: Failed to read schema document错误的解决方法)

    今天配置Spring的xml出现了错误 Multiple annotations found at this line: - schema_reference.4: Failed to read sc ...

随机推荐

  1. linux内核神级list

    源码: #ifndef _LINUX_LIST_H #define _LINUX_LIST_H /* * Simple doubly linked list implementation. * * S ...

  2. Android中对日期进行排序

    最近在项目中需要将读取的数据按照时间的降序进行排序. 具体的步骤如下: 1.读取数据,存入List中 2.取出数据中的时间戳,由String转换成Date 3.使用冒泡排序对List中元素按照Date ...

  3. grunt构建前端自动化的开发环境

    废话不多说.直奔主题. 1.安装node. 别问为什么.如果你不知道,说了你还是不知道. 别问怎么安装,自己去百度. 2.安装grunt_CLI. 安装完node,并且安装成功了,后.下载grunt_ ...

  4. (medium)LeetCode 220.Contains Duplicate III

    Given an array of integers, find out whether there are two distinct indices i and j in the array suc ...

  5. (转)C#picturebox控件使用

    PictureBox是C#常用图片空间,本文是学习中搜集网络资料的一些整理和记录 1,PictureBox加载图片 using System.Drawing; //方式1,从图片文件载入 //下面的路 ...

  6. dubbo服务框架学习

    ====================================================================================== 1.提供注册服务.消费者可 ...

  7. image onclick

    onclick="this.src+='?rand='+Math.random();"  style="cursor: pointer; vertical-align: ...

  8. 程序员必备:Oracle日常维护命令

        上一篇讲了Linux的日常维护命令,这篇讲讲Oracle的日常维护命令.工作中需要使用Oracle数据库的童鞋们,相信或多或少都需要对Oracle做一些基本的维护操作,例如导入导出总该有吧?( ...

  9. [ CodeVS冲杯之路 ] P1092

    不充钱,你怎么AC? 题目:http://codevs.cn/problem/1092/ 嗯,这道题有一定难度啊,需要先用扩展欧几里得算法求出逆元,然后按照大小构一颗带边权为小时数的树 树链剖分后在树 ...

  10. 静态库制作.a .framework

    一.静态库 .a 制作   1.新建一个Cocoa Touch Static Library         2.往里面添加文件,或者自己新建         3.添加一个Headers Phase ...