@mgraph是接近,但如果你想d O此按鈕上單擊
在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 class="post-body"></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 class="post-body"></div>
<button id="yes" type="button">Yes</button>
<button id="no" type="button">No</button>
你的ajax代碼在哪裏? – Sarfraz
你試過Google搜索嗎? – hjpotter92
@ Sarfraz - 這就是我想知道的。 Ajax代碼。 @ T恤老兄是的,我試着從這麼多天開始。我終於來到了這裏。 –