js Ajax Àà
Éú»îÒª¿ìÀÖ
/*
κÑÔAJAX Àà
ʹÓ÷½·¨:
<mce:script type="text/javascript"><!--
var classAjax = new Ajax(sUrl,sRecvTyp,sQueryString,oResultFunc);
classAjax.post();//post·½Ê½·¢ËÍÊý¾Ý
classAjax.get();//get·½Ê½·¢ËÍÊý¾Ý
//sUrl·¢Ë͵ØÖ·
//sRecvTyp ½ÓÊÜÊý¾ÝÀàÐÍ:0Ϊxml 1Ϊtext
//oResultFunc ·µ»Ø½á¹û´¦Àíº¯Êý
// --></mce:script>
Ó¦ÓÃʵÀý£º
<mce:script type="text/javascript"><!--
var ajax1 = new Ajax("1.asp",0,"id="+id,bacal);
ajax1.post();
function bacal(rexm){
//·µ»ØÊý¾Ý´¦Àíº¯Êý;
}
// --></mce:script>
*/
function Ajax(sUrl,sRecvTyp,sQueryString,oResultFunc) {
this.Url = sUrl;
this.QueryString = sQueryString;
this.XmlHttp = this.createXMLHttpRequest();
if (this.XmlHttp == null) {
alert("erro");
return;
}
var objxml = this.XmlHttp;
objxml.onreadystatechange = function (){Ajax.handleStateChange(objxml,sRecvTyp,oResultFunc)};
}
Ajax.prototype.createXMLHttpRequest = function() {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
try { return new XMLHttpRequest(); } catch(e) {}
return null;
}
Ajax.prototype.createQueryString = function () {
var queryString = this.QueryString;
return queryString;
}
Ajax.prototype.get = function () {
sUrl = this.Url;
var queryString = sUrl+"?timeStamp=" + new Date().getTime() + "&" + this.createQueryString();
this.XmlHttp.open("GET",queryString,true);
this.XmlHttp.send(null);
}
Ajax.prototype.post = function() {
sUrl = this.Url;
var sUrl = sUrl + "?timeStamp=" + new Date().getTime();
var queryString = this.createQueryString();
this.XmlHttp.open("POST",sUrl,true);
this.XmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
this.XmlHttp.send(queryString);
}
Ajax.handleStateChange = function (XmlHttp,sRecvTyp,oResultFunc) {
if (XmlHttp.readyState == 4) {
if (XmlHttp.status == 200) {
oResultFunc(sRecvTyp?XmlHttp.responseXML:XmlHttp.responseText);
} else {
alert("ÄúËùÇ
Ïà¹ØÎĵµ£º
function createXMLHttpRequest(){
if(window.ActiveXObject){
http = new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
& ......
ʹÓÃAjaxÖвéѯÊý¾Ý¿âʱ£¬Ö»µÚÒ»´Î²éѯÁËÊý¾Ý¿â£¬ÒÔºóÔÙÓÐÇëÇó¾Í²»Ìá½»¸ø·þÎñÆ÷´¦ÀíÁË
ҳͷµÄÇ建´æ±êǩûÆð×÷ÓÃ
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
½â¾ö·½·¨£º
1£º¼Óʱ¼ä´Á var url ......
<script language="javascript" type="text/javascript">
var xmlHttp = null;
function CreateXMLHttp()
{
......
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>JavaScript Sample</title>
<link rel="stylesheet" type="text/css" href="main.css" media="all">
<sc ......
1.ʲôÊÇAjax?
AjaxµÄÈ«³ÆÊÇ£ºAsynchronousJavaScript+XML
2.AjaxµÄ¶¨Ò壺
Ajax²»ÊÇÒ»¸ö¼¼Êõ£¬Ëüʵ¼ÊÉÏÊǼ¸ÖÖ¼¼Êõ£¬Ã¿ÖÖ¼¼Êõ¶¼ÓÐÆä¶ÀÌØÕâ´¦£¬ºÏÔÚÒ»Æð¾Í³ÉÁËÒ»¸ö¹¦ÄÜÇ¿´óµÄм¼Êõ¡£
3.Ajax°üÀ¨£º
XHTMLºÍCSS
ʹÓÃÎĵµ¶ÔÏóÄ£ÐÍ(DocumentObjectModel)×÷¶¯Ì¬ÏÔʾºÍ½»»¥
ʹÓÃXMLºÍXSLT×öÊý¾Ý½»»¥ ......