栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用Ajax在DIV中重新加载MySQL数据

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Ajax在DIV中重新加载MySQL数据

@mgraph已关闭,但如果要在按钮上执行此操作,请单击

post.php中

//$UserOption will be Yes/No for button clicks or empty string for first load of the page$UserOption = $_REQUEST['UserClicked'];//Id will be set if a vote has been clicked or empty string if it's the first load$Id = $_REQUEST['Id'];//(Do something with $UserOption)$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(){   update(null,null);})function update(Id, Vote) {    $(".post-body").eq(0).load("post.php?UserClicked=" + Vote + "&Id=" + Id);}</script>

HTML

<div ></div><button type="button" onclick="update(1, 'Yes');">Yes</button><button type="button" onclick="update(1, 'No');">No</button><button type="button" onclick="update(2, 'Yes');">Yes</button><button type="button" onclick="update(2, 'No');">No</button>

备用HTML / JS

<script type="text/javascript">$(document).ready(function(){    $("#yes").click(function(){        update('Yes');    })    $("#no").click(function(){        update('No');    })    update();})function update(Vote) {    $(".post-body").eq(0).load("post.php?UserClicked=" + Vote);}</script><div ></div><button id="yes" type="button">Yes</button><button id="no" type="button">No</button>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/404079.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号