有人可以告訴我爲什麼我的按鈕不工作?我在我的博客上附加了一個類似按鈕,並使用Ajax將每個相似的計數器發送到mySQL數據庫中。但是,顯然這不起作用。這裏是我的jQuery函數:jquery阿賈克斯按鈕
$(document).ready(fuction() {
function likefunction(catch_blog_id) {
var count = 1;
var catch_id = catch_blog_id;
var status = $('#likelink').html();
var vardata = 'count' + count + '&catch_id' + catch_id;
if (status == "Like") {
$.ajax({
type: "POST",
url: 'like.php',
data: vardata,
success: function() {$('#likelink').html("Unlike");}
})
} else {
$.ajax({
type: "POST",
url: 'unlike.php',
data: vardata,
success: function() {$('#likelink').html("Like");}
})
}
}
})
</script>
這裏是.php文件:一個用於類似功能和其他的不同功能==
like:
<?php
include_once('connectserver.php');
$catch_blog_id = $_POST['catch_id'];
$catch_count = $_POST['count'];
$query_blog = mysql_query("SELECT `likes` FROM `posts` WHERE `id` = '$catch_blog_id'");
while($get_rows = mysql_fetch_assoc($query_blog)) {
$likes = $get_rows['likes'];
$likes = (int)$likes;
$likes++;
mysql_query("UPDATE `posts` SET `likes` = '$likes' WHERE `id` = '$catch_blog_id'");
}
?>
unlike:
<?php
include_once('connectserver.php');
$catch_blog_id = $_POST['catch_id'];
$catch_count = $_POST['count'];
$query_blog = mysql_query("SELECT `likes` FROM `posts` WHERE `id` = '$catch_blog_id'");
while($get_rows = mysql_fetch_assoc($query_blog)) {
$likes = $get_rows['likes'];
$likes = (int)$likes;
$likes--;
mysql_query("UPDATE `posts` SET `likes` = '$likes' WHERE `id` = '$catch_blog_id'");
}
?>
這裏的一部分用於存儲類似按鈕的html文件:
echo「
贊評論」;
您的javascript代碼中的計數總是等於1(在變量中'vardata')。此外,您需要在$ _POST數據中的變量和值之間有相同的符號。 – Sablefoste 2014-09-21 23:57:44
計數是多餘的。我shud已刪除該部分...忽略計數..我將後端sql數據設置爲0,並通過從查詢中提出它來增加它 – 2014-09-22 00:05:58