0

How do I get from a javascript to php using xmlhttprequest()? I just want to call a php script triggered by an event listener.

XMLHttpRequest("GET","load.php",true); 

Doesn't seem to get any of the code to run. Does it have something to do with the php header?

1 Answer 1

1

Here you can find another example: w3school example or w3school xml dom main page

<script>
function loadXMLDoc()
{
   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=function()
   {
     if (xmlhttp.readyState==4 && xmlhttp.status==200)
     {
       document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
     }
   }
   xmlhttp.open("GET","xmlhttp_info.txt",true);
   xmlhttp.send();
}
</script>
</head>
<body>

<h2>Using the XMLHttpRequest object</h2>
<div id="myDiv"></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>

</body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.