• <sub id="h4knl"><ol id="h4knl"></ol></sub>
    <sup id="h4knl"></sup>
      <sub id="h4knl"></sub>

      <sub id="h4knl"><ol id="h4knl"><em id="h4knl"></em></ol></sub><s id="h4knl"></s>
      1. <strong id="h4knl"></strong>

      2. 原生ajax調用數據實例簡單講解

        時間:2020-11-09 17:38:04 AJAX 我要投稿

        原生ajax調用數據實例簡單講解

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

          一.兼容瀏覽器部分

          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()產生和getTime類似的效果; url+=""+new Date().getTime(); this.req=null; this.url=url; //這個回調函數就是在數據在頁面上的更新函數; this.onload=function() { //domEl是ID為#test的dom元素; var domEl=document.getElementById("test"); //除了用responseText屬性,也可以使用responseXml獲得一張數據表; 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調用數據實例介紹,希望對大家的學習有所幫助。

        【原生ajax調用數據實例簡單講解】相關文章:

        1.分享解析ajax事件的調用順序

        2.AJAX請求類實例代碼

        3.Ajax+PHP如何簡單基礎入門實例教程

        4.JavaScript實例講解

        5.講解PAT配置「實例」

        6.通過JQuery的Ajax調用一般處理程序

        7.C#開發和調用Web Service實例

        8.零基礎學習AJAX之AJAX簡單框架

        国产高潮无套免费视频_久久九九兔免费精品6_99精品热6080YY久久_国产91久久久久久无码
      3. <sub id="h4knl"><ol id="h4knl"></ol></sub>
        <sup id="h4knl"></sup>
          <sub id="h4knl"></sub>

          <sub id="h4knl"><ol id="h4knl"><em id="h4knl"></em></ol></sub><s id="h4knl"></s>
          1. <strong id="h4knl"></strong>

          2. 亚洲第一福利网站 | 在线播放一区二区不卡三区 | 中文字幕日本久久2019 | 天堂aⅴ日韩欧美国产 | 午夜在线观看的那种网站 | 亚洲国产成久久综合片 |