永发信息网

怎么获取通过ajax请求的html代码

答案:2  悬赏:20  手机版
解决时间 2021-01-03 22:16
  • 提问者网友:聂風
  • 2021-01-02 21:58
怎么获取通过ajax请求的html代码
最佳答案
  • 五星知识达人网友:傲气稳了全场
  • 2021-01-06 23:16
利用回调函数获取服务器返回的结果<br>JavaScript code<br>var xmlHttp;<br><br>    function createXMLHttpRequest() {<br>    if(window.XMLHttpRequest) {<br>    xmlHttp = new XMLHttpRequest();<br>    } else if (window.ActiveXObject) {<br>    xmlHttp = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);<br>    }<br>    }<br><br>    function routeList(){<br>    createXMLHttpRequest();<br>    url = &quot;manage_action_class.php?&quot;&amp;ran=&quot;+Math.random();  //后端请求页面<br>    method = &quot;GET&quot;;   //传输方式<br>    xmlHttp.open(method,url,true);<br>    xmlHttp.onreadystatechange = showList;   //这里为回调函数<br>    xmlHttp.send(null);<br>    }<br><br>    function showList(){<br>    if (xmlHttp.readyState == 4){<br>    if (xmlHttp.status == 200){<br>    var text = xmlHttp.responseText;  //这里获得服务器返回的数据<br>    document.getElementById(&quot;route&quot;).innerHTML = text;  //将数据放入html指定div中<br>    }else {<br>    alert(&quot;response error code:&quot;+xmlHttp.status);<br>    }<br>    }<br>    }
全部回答
  • 1楼网友:鱼芗
  • 2021-01-07 00:55
&lt;script type=&quot;text/javascript&quot;&gt; function ajaxfunction() { var xmlhttp; try { // firefox, opera 8.0+, safari xmlhttp=new xmlhttprequest(); } catch (e) { // internet explorer try { xmlhttp=new activexobject(&quot;msxml2.xmlhttp&quot;); } catch (e) { try { xmlhttp=new activexobject(&quot;microsoft.xmlhttp&quot;); } catch (e) { alert(&quot;您的浏览器不支持ajax!&quot;); return false; } } } xmlhttp.onreadystatechange=function() { if(xmlhttp.readystate==4) { document.myform.time.value=xmlhttp.responsetext; } } xmlhttp.open(&quot;get&quot;,&quot;time.asp&quot;,true);//请求地址是&quot;time.asp&quot; xmlhttp.send(null); } &lt;&amp;#47;script&gt;
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯