AJAX类
AJAX类
// AJAX类
function AJAXRequest() {
var xmlObj = false;
var CBfunc,ObjSelf;
ObjSelf=this;
try { xmlObj=new XMLHttpRequest; }
catch(e) {
try { xmlObj=new ActiveXObject("MSXML2.XMLHTTP"); }
catch(e2) {
try { xmlObj=new ActiveXObject("Microsoft.XMLHTTP"); }
catch(e3) { xmlObj=false; }
}
}
if (!xmlObj) return false;
this.method="POST";
this.url;
this.async=true;
this.content="";
this.callback=function(cbobj) {return;}
this.send=function() {
if(!this.method||!this.url||!this.async) return false;
xmlObj.open (this.method, this.url, this.async);
if(this.method=="POST") xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlObj.onreadystatechange=function() {
if(xmlObj.readyState==4) {
if(xmlObj.status==200) {
ObjSelf.callback(xmlObj);
}
}
}
if(this.method=="POST") xmlObj.send(this.content);
else xmlObj.send(null);
}
}
类名:AJAX
创建方法:var ajaxobj=new AJAX;,如果创建失败则返回false
属性:method - 请求方法,字符串,POST或者GET,默认为POST
url - 请求URL,字符串,默认为空
async - 是否异步,true为异步,false为同步,默认为true
content - 请求的内容,如果请求方法为POST需要设定此属性,默认为空
callback - 回调函数,即返回响应内容时调用的函数,默认为直接返回,回调函数有一个参数为XMLHttpRequest对象,即定义回调函数时要这样:function mycallback(xmlobj)
方法:send() - 发送请求,无参数
一个例子:
<script type="text/javascript" src="ajaxrequest.js"></script>
<script type="text/javascript">
var ajaxobj=new AJAXRequest; // 创建AJAX对象
ajaxobj.method="GET"; // 设置请求方式为GET
ajaxobj.url="default.asp" // URL为default.asp
// 设置回调函数,输出响应内容
ajaxobj.callback=function(xmlobj) {
document.write(xml
相关文档:
1. 镜头迁徙应当应用实施镜头重定向的Response.Redirect而不是Server.Transfer,由于Server.Transfer不改变IE客户端URL,能以致ASP.NET AJAX客户端脚本访问资源的时分出现URL错处。
二.在服务器端登记脚本和掩藏字段应当施用种ScriptManager,而不是Page.ClientScript对象,由于Page.ClientScript的步骤是将脚本登记 ......
从数据库my中的username用户表里验证:
checkusername.html:
<!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>
<meta http-equiv="Content-Type" conte ......
PHP 5.2 及以上版本提供了 json_encode 和 json_decode 函数,相当好用。
而之前的版本则需要下载网友们自行开发的库(有兴趣的可以看下 http://code.itlearner.com/php/JSON-class.html )
可以参考如下这个方法来在低版本上扩充这两个函数:
if (!function_exists('json_encode') && !function_exists('j ......
利用AJAX动态获取当前时间,客户端time.php,服务器端time_check.php
客户端代码:
<!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>
<meta http-equiv=" ......