0

Hi,

I have been working on trying to figure out, how to call a php function in javascript, for about two weeks.
PS: I don't have code to post because I really don't know how to implement this.

Edited by sree jith

5
Contributors
4
Replies
26
Views
4 Years
Discussion Span
Last Post by diafol
0

Simple script here... [Took from w3schools]

<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc()
{
var xmlhttp;
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","ajax_info.php",true);
xmlhttp.send();
}
</script>
</head>
<body>

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

</body>
</html>
0

The vanilla js can be a bit intimidating if you're new to it. To get a quick result, while taking time to learn 'proper js', you could use jQuery and it's .ajax method (or its shortcut methods). Other libraries will have similar methods.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.