0

There are many examples of tabs that can dynamically load content into a div without leaving the parent page.

However, all of the examples I could find use ajax with jquery, or some other library. I am trying to avoid using any libraries.

Does anyone have ajax only examples of tabs loading content into a div?

thanks.

nomaam
  • 1,213
  • 2
  • 22
  • 37

1 Answers1

1

Ajax without jQuery

Example:

<!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>
Prateek
  • 6,785
  • 2
  • 24
  • 37