PHP頁面:JSON編碼失敗
<?php
include "linkpassword.inc";
function showVotes()
{
$showresult = mysql_query("SELECT * from mms") or die("Invalid query: " . mysql_error());
$row = mysql_fetch_assoc($showresult);
}
function addVote()
{
$sql= "UPDATE mms SET votes = votes+1 WHERE color = '".$_POST['color']."'";
$result= mysql_query($sql) or die(mysql_error());
return $result;
}
addVote();
showVotes();
?>
我試圖讓陣列的輸出加載到一個JavaScript頁面,在這裏我可以打破了數組已分配給他們的ID單獨的div。這是我試過的
<script>
$(document).ready(function() {
$('.answer').click(function (e) {
var color = $(this).attr("data-color");
$.ajax({
type: 'POST',
url: 'mm.php',
data: { color: color},
dataType: 'json',
cache: false,
success: function(showVotes) {
$('#rvotes').html(showVotes[0]);
},
error: function (jqXHR) {
}
})
})
});
</script>
我在哪裏出錯?
你從來沒有初始化$結果,只有$迴應 – kennypu 2013-03-05 02:28:13
你也似乎有兩次沒有理由的相同的查詢。 – lmortenson 2013-03-05 02:28:57
如果你解釋了*出錯了,這將有所幫助。例如。你期望*會發生什麼,以及實際發生了什麼。目前,我們必須猜測。 – Hamish 2013-03-05 02:37:33