色www,五月婷婷深爱五月,午夜国产一级片,色噜噜综合,国产大胸无码视频,清纯美女被操黄网站在线观看,波多野结衣av高清一区二区三区

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

時間:2024-06-22 16:10:20 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ù)實例簡單講解】相關文章:

Ajax使用JSON數(shù)據(jù)格式案例分析01-10

實例講解托福閱讀推斷題技巧06-20

簡單實用的演講技巧講解09-04

java調(diào)用cmd命令01-29

AJAX的工作原理及優(yōu)缺點08-16

Windows網(wǎng)絡診斷怎么調(diào)用10-02

使用ajax操作JavaScript對象的方法09-28

關于Ajax技術原理的幾點總結01-10

小升初數(shù)學簡單統(tǒng)計表知識講解01-28

基于ajax實現(xiàn)無刷新分頁的方法10-15