我在我的网站上有几个这个脚本的克隆,它们可以工作。该功能是启用喜欢,关注等(任何需要参考表来存储喜欢,关注等的东西)。问题在于我的喜欢功能它运行.post 12次。我的后续脚本具有相同的 jquery 代码,但不这样做。所以我求助于检查我的 fave.php/unfave.php 文件,但我找不到任何错误。它与我的 follow.php/unfollow.php 文件相同。谁能发现或意识到这种奇怪的行为?
基本上,我的数据库中有 12 个条目。为什么?
最喜欢的.js
$(document).ready(function(){
$(function(){
$(".fvspan").on("click", ".favebtn", function(){
var fvs = $(this).attr('id');
if(fvs)
{
$.ajax({
type: "POST",
url: "/mobile/inc/vdfave.php",
data: "fvs=" + fvs,
cache: false,
success: function(data){
$("span#" + fvs + ".fvspan").html("<img id='" + fvs + "' class='favebtn-un' src='/assets/faved.png' height='50px'>");
}
});
}
else { }
});
});
$(function(){
$(".fvspan").on("click", ".favebtn-un", function(){
var fvs = $(this).attr('id');
if(fvs)
{
$.ajax({
type: "POST",
url: "/mobile/inc/vdunfave.php",
data: "fvs=" + fvs,
cache: false,
success: function(data){
$("span#" + fvs + ".fvspan").html("<img id='" + fvs + "' class='favebtn' src='/assets/fave.png' height='50px'>");
}
});
}
else { }
});
});
});
vdfave.php
<?php
session_start();
//Make an SQL connection
include('/home/bfreak/www/inc/dbc.php');
$myself = $_SESSION['username'];
$ref = $_POST['fvs'];
$date = date("Y-m-d h:i:s");
if (!isset($_SESSION['loggedIn'])) { }
else{$myinfo = mysql_query("SELECT * FROM users WHERE username = '$myself'");}
while($myid1 = mysql_fetch_array($myinfo))
{
$myid = $myid1['id'];
//Insert form data into database with corresponding structure, in respective order, of SQL columns.
$fvd = "INSERT INTO faves (vid, usr, date) VALUES ('$ref', '$myid', '$date')";
if (!mysql_query($fvd, $con)) {die('Fatal Error: ' . mysql_error());}
}
mysql_close($con);
?>