我需要制作一个像 fmylife.com 中那样的适度系统。基本上我遇到的问题是使用 Ajax(不刷新页面)将 MySQL 查询加载到 div 中。 MySQL查询
$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>
按"is"或“否”按钮时应重新加载此数据。提前致谢。
最佳答案
在 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>
关于php - 使用 Ajax 在 DIV 中重新加载 MySQL 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11070607/