亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Ajax 數(shù)據(jù)請求的簡單分析

 更新時間:2011年04月05日 21:42:51   作者:  
Ajax使用的關(guān)鍵對象是XmlHttpRequest對象,但是涉及到跨瀏覽器的的問題,所以,需要創(chuàng)建一個具兼容性的對象
比如:
復(fù)制代碼 代碼如下:

function xmlHttpR(){
var xmlhttp;
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}
else{
try{xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")}
catch(e){
try{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){return null;
}
}
return xmlhttp;

這樣就基本上能創(chuàng)建一個跨瀏覽器的對象了;
下面是ajax的簡單運用,利用XmlHttpRequest對象完成;
復(fù)制代碼 代碼如下:

var ajaxEl=new Object();
//ajaxEl是自定義的命名空間;
ajaxEl.contentLoad=function(url){
//IE瀏覽器下,會啟用緩存,這里url加入date字段就是為了防止IE使用緩存,當然也可以使用Math.random()產(chǎn)生和getTime類似的效果;
url+="?date="+new Date().getTime();
this.req=null;
this.url=url;
//這個回調(diào)函數(shù)就是在數(shù)據(jù)在頁面上的更新函數(shù);
this.onload=function(){
//domEl是ID為#test的dom元素;
var domEl=document.getElementById("test");
//除了用responseText屬性,也可以使用responseXml獲得一張數(shù)據(jù)表;
domEl.innerHTML=this.req.responseText;
}
this.Xmlhttp(url);
}
ajaxEl.contentLoad.prototype={
Xmlhttp:function(url){
if(window.XMLHttpRequest){
this.req=new XMLHttpRequest();
}
else{
try{this.req=new ActiveXObject("Msxml2.XMLHTTP")}
catch(e){
try{this.req=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){return null;
}
}
}
if(this.req){
var xmlR=this;
this.req.onreadystatechange=function(){
if(xmlR.req.readyState===4){
xmlR.onload.call(xmlR);
}
}
this.req.open("GET",url,true);
this.req.send(null);
}
}
}
var xmlE=new ajaxEl.contentLoad("main.php");

main.php里面,我這里設(shè)置的比較簡單的示例代碼:在頁面上就會顯示一個類似:now! time is:05:18:10 am 2011,這樣可動態(tài)變化的時間。
復(fù)制代碼 代碼如下:

echo "now! time is:".date("H:i:s a Y");

相關(guān)文章

最新評論