av手机免费在线观看,国产女人在线视频,国产xxxx免费,捆绑调教一二三区,97影院最新理论片,色之久久综合,国产精品日韩欧美一区二区三区

AJAX

原生ajax調(diào)用數(shù)據(jù)實例簡單講解

時間:2024-07-19 18:42:05 AJAX 我要投稿
  • 相關推薦

原生ajax調(diào)用數(shù)據(jù)實例簡單講解

  由于jQuery的盛行,現(xiàn)在使用較多的是jQuery封裝好了的ajax,因為解決了瀏覽器兼容性問題,這對程序員來說就等于去掉了一個心頭大患,但并非原生ajax就銷聲匿跡,并且本人感覺還是對原生的ajax有所了解的好,下面就是一段ajax數(shù)據(jù)調(diào)用的實例代碼,非常的簡單,初學者可以參考一下。代碼如下:

  一.兼容瀏覽器部分

  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; }

  以上能夠返回一個兼容各個瀏覽器的對象。

  二.實例代碼

  var ajaxEl=new Object(); //ajaxEl是自定義的命名空間; ajaxEl.contentLoad=function(url){ //IE瀏覽器下,會啟用緩存,這里url加入date字段就是為了防止IE使用緩存,當然也可以使用Math.random()產(chǎn)生和getTime類似的效果; url+=""+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");

  三.php中的代碼

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

  以上就是關于原生ajax調(diào)用數(shù)據(jù)實例介紹,希望對大家的學習有所幫助。

【原生ajax調(diào)用數(shù)據(jù)實例簡單講解】相關文章:

高爾夫技巧講解11-15

導游講解技巧04-09

足球籬笆戰(zhàn)術講解02-20

泡茶的詳細步驟講解06-07

吉他入門技巧講解01-12

關于OrCad原理圖設計中模塊化的調(diào)用07-12

資本運作模式的講解01-14

德語基本語法知識講解08-12

網(wǎng)球接發(fā)球的技巧講解11-07

象棋怎么下及口訣講解11-09