Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
715 views
in Technique[技术] by (71.8m points)

php - Reload MySQL data inside a DIV using Ajax

I need to make a moderate system like the one in fmylife.com. Basically the problem I have is loading the MySQL query using Ajax (without page refreshing) in to a div. MySQL query

$sql = mysql_query(“SELECT * FROM posts WHERE active =’0’” LIMIT 1) or die (mysql_error());
$row = mysql_fetch_array($sql);

HTML

<div class=”post-body”><?php echo $row[‘sitepost’];?></div>

this data should be reloaded when pressing "yes" or "no" buttons. thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

in post.php:

$sql = mysql_query("SELECT * FROM posts WHERE active ='0' LIMIT 1") or die (mysql_error());
$row = mysql_fetch_array($sql);
echo $row['sitepost'];

JS:

<script type="text/javascript">
$(document).ready(function(){
   $("#yes").click(function(){
      $(".post-body").eq(0).load("post.php");
   })
})
</script>

HTML:

<div id="yes">YES</div>
<div class="post-body"></div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...