对Ajax的一些基本理解
一、ajax的入门
1、XMLHttpRequest对象的使用(使用XMLHttpRequest解析xml文件)
onreadystatechange
指定当readyState属性改变时的事件处理句柄
open()
创建一个新的http请求,并指定此请求的方法、URL等信息
send()
发送请求到http服务器并接收回应
readyState
返回XMLHTTP请求的当前状态
status
返回当前请求的http状态码
responseText
将响应信息作为字符串返回
responseXML
将响应信息格式化为Xml Document对象并返回
out回应客户
1、“添加新项” 新建一个XML文件来存放要被调用的数据。
XMLFile.xml
<?xml version="1.0" encoding="utf-8" ?>
<response>
<res>
对不起,登录失败!
</res>
</response>
2、“添加新项” 新建一个JSP页,添加代码:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!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>Ajax异步调用</title>
</head>
<body>
<div style="background-color:Yellow" id="mytext">Ajax异步调用
</div>
<input type="button" value="更新" onclick="startHTTP()" />
</body>
</html>
<script type="text/javascript">
var XMLHttpReq;
function createHTTP(){
//根据不同的浏览器创建XMLHttpRequest
if(window.ActiveXObject)//ie浏览器
{
XMLHttpReq=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){//其他浏览器
XMLHttpReq=new XMLHttpRequest();
}
}
//开始调用
function startHTTP()
{
相关文档:
该实例首先需要创建数据库,数据库Test唯一表test,该表具有三个列分别为c1,c2,c3, int型,请自行建立数据库并插入几行测试数据。
然后我们希望能将数据库中的数据读取出来,我在此处只是将数据库数据以数据集的方式存放在本地中, ......
What is AJAX
This section is for those who have no idea what AJAX is. If you don’t fall into this category, feel free to skip to the next section.
AJAX stands for asynchronous JavaScript and XML. If you see another term XHR, which is shorthand for XML HTTP request, it’s the same thing. ......
多数 Web 应用程序都使用请求/响应模型从服务器上获得完整的 HTML 页面。常常是点击一个按钮,等待服务器响应,再点击另一个按钮,然后再等待,这样一个反复的过程。有了 Ajax 和 XMLHttpRequest 对象,就可以使用不必让用户等待服务器响应的请求/响应模型了。本文中,Brett McLaughlin 介绍了如何创建能够适应不同浏览器的 ......