Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 没有jquery的Ajax选项卡?_Javascript_Html_Ajax - Fatal编程技术网

Javascript 没有jquery的Ajax选项卡?

Javascript 没有jquery的Ajax选项卡?,javascript,html,ajax,Javascript,Html,Ajax,有许多选项卡示例可以在不离开父页面的情况下将内容动态加载到div中 然而,我能找到的所有示例都使用ajax和jquery,或者其他一些库。我尽量避免使用任何库 有没有人有只使用ajax的选项卡将内容加载到div的示例 谢谢。没有jQuery的Ajax 例如: <!DOCTYPE html> <html> <head> <script> var xmlhttp; function loadXMLDoc(url,cfunc)

有许多选项卡示例可以在不离开父页面的情况下将内容动态加载到div中

然而,我能找到的所有示例都使用ajax和jquery,或者其他一些库。我尽量避免使用任何库

有没有人有只使用ajax的选项卡将内容加载到div的示例


谢谢。

没有jQuery的Ajax

例如:

<!DOCTYPE html>
 <html>
  <head>
   <script>
    var xmlhttp;
    function loadXMLDoc(url,cfunc)
    {
     if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
      } 
     else
      {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=cfunc;
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
   }

  function myFunction()
  {
   loadXMLDoc("ajax_info.txt",function()
   {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
     {
       document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
     }
   });
  }
 </script>
 </head>
<body>

<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="myFunction()">Change Content</button>

 </body>
</html>

var-xmlhttp;
函数loadXMLDoc(url,cfunc)
{
if(window.XMLHttpRequest)
{//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
} 
其他的
{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
onreadystatechange=cfunc;
open(“GET”,url,true);
xmlhttp.send();
}
函数myFunction()
{
loadXMLDoc(“ajax_info.txt”,function())
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
document.getElementById(“myDiv”).innerHTML=xmlhttp.responseText;
}
});
}
让AJAX更改此文本
更改内容