XMLHttpRequest学习笔记一
来源:互联网 发布:手机 知乎 编辑:程序博客网 时间:2024/05/17 08:49
通过XMLHttpRequest从服务端获取数据,并以表格方式进行展现,代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";response.setHeader("Pragma","No-Cache");response.setHeader("Cache-Control","No-Cache");response.setHeader("Expires","0");%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My JSP 'testxmlhttprequest.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--> </head> <body> <!-- 请求服务器端的xml数据文件,并以表格方式进行展现 --> <script type="text/javascript"> var xmlHttpRequest; function createXMLHttpRequest() { //support IE7+,firefox,Chrome,Opera,Safari and so on if (window.XMLHttpRequest) { xmlHttpRequest = new XMLHttpRequest(); } else { //support IE6,IE5 //xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); xmlHttpRequest = new ActiveXObject("MSXML2.XMLHTTP.3.0"); } return xmlHttpRequest; } //创建xmlhttp请求对象 xmlHttpRequest = createXMLHttpRequest(); xmlHttpRequest.open("GET","webpage/book.xml",false); xmlHttpRequest.send(); // alert(xmlHttpRequest.responseText); var xmldom = xmlHttpRequest.responseXML; //解析XMLDOM var e_books = xmldom.getElementsByTagName("books")[0]; var e_book_array = e_books.childNodes; document.writeln("<table border='1'>"); document.writeln("<tr><th>ID</th><th>Name</th><th>Author</th></tr>"); for(var i=0; i<e_book_array.length; i++) { var e = e_book_array[i]; document.writeln("<tr><td>" + e.getElementsByTagName("id")[0].childNodes[0].nodeValue + "</td><td>" + e.getElementsByTagName("name")[0].childNodes[0].nodeValue + "</td><td>" + e.getElementsByTagName("author")[0].childNodes[0].nodeValue + "</td></tr>"); } document.writeln("</table>"); </script> </body></html>
- XMLHttpRequest学习笔记一
- XMLHttpRequest对象学习笔记(一)
- AJAX学习笔记一(认识XMLHttpRequest对象)
- XMLHttpRequest学习笔记
- XMLHTTPRequest使用【学习笔记】
- AJAX 学习笔记(1) XMLHttpRequest对象概述
- Java Web学习笔记(六)XMLHttpRequest
- [学习笔记]XMLHttpRequest实现局部刷新
- ajax学习笔记:ajax原态-XmlHttpRequest
- XMLHTTPRequest笔记
- AJAX笔记一创建XMLHttpRequest对象,以及XMLHttpRequest对象的常用属性
- AJAX(XMLHttpRequest)跨域请求笔记(一)
- jQuery入门学习一:原始XMLHttpRequest方法回顾
- 学习笔记---使用prototype.js扩展struts标签实现xmlhttprequest
- ajax学习笔记---XMLHttpRequest的属性和方法
- Ajax学习笔记——XMLHttpRequest对象发送request
- AJAX学习笔记:创建XMLHttpRequest对象的五步骤
- AJAX学习笔记:创建XMLHttpRequest对象的五步骤
- hdu step 1.1.2.7
- 实用算法实现-第 7 篇Trie树
- C#无边框窗体最大化后档住任务栏的解决办法
- 使用可传输表空间的特性复制数据!
- SQLserver2005以身份认证方式登录的一些配置
- XMLHttpRequest学习笔记一
- joj1006
- 解决方案:sqlite 对datetime型的数据读取错误
- 由1-7的随机整数函数构造1-10随机整数函数
- statement by the president on thepassing of steve jobs
- 排序qsort
- 实用算法实现-第8篇后缀树和后缀数组 [1简介]
- Steve Jobs' Commencement address
- C#iphone UILabel 的使用