Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do php query with ajax

Tags:

ajax

php

I'd like to do a sql query with ajax so I don't need to reload the page / load a new page.

So basicly I need to call a php page with ajax. And it would be great if there could be a way to reload a count of amount of rows in a table too.

Edit: to make it more clear, it should be able to do something along the lines of when you click the Like button on Facebook.

Thanks

like image 600
Deniz Zoeteman Avatar asked Mar 08 '26 08:03

Deniz Zoeteman


1 Answers

<html>
<head>
<script type="text/javascript">
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("your_div").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","ajax_file.php",true);
xmlhttp.send();
}
</script>
</head>
<body>

<div id="myDiv">here are your contents</div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>

</body>
</html>
like image 150
genesis Avatar answered Mar 10 '26 21:03

genesis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!