191
rated 0 times
[
198]
[
7]
/ answers: 1 / hits: 52297
/ 10 Years ago, tue, march 25, 2014, 12:00:00
I want to get data from mysql database using php and jquery ajax. 'process.php' is the php file which connects to database and get mysql data. It works when it is run separately, but when called using ajax it doesn't work. Can someone please help to correct error? Here is my html file:
<html>
<head>
<script type=text/javascript src=js/jquery-1.11.0.min.js></script>
<script type=text/javascript>
$(document).ready(function(){
function showRoom(){
$.ajax({
type:POST,
url:process.php,
data:{action:showroom},
success:function(data){
$(#content).html(data);
}
});
}
showRoom();
});
</script>
</head>
<body>
<div id=content></div>
</body>
</html>
Here is my process.php file
<?php
$link=mysqli_connect(localhost,root,raspberry,homebot);
if (mysqli_connect_errno())
echo Failed to connect to MySQL: . mysqli_connect_error();
$action=$_POST[action];
if($action==showroom){
$query=SELECT * FROM user;
$show=mysqli_query($link,$query) or die (Error);
while($row=mysqli_fetch_array($show)){
echo <li>$row['name']</li>;
}
}
?>
More From » php