我有一张类似按钮的图片,点击后,应将分数更新为1。 我正在使用ajax来执行此操作。 但是,当我点击图像时没有任何反应。当我将鼠标悬停在图像上时,指针甚至不会变为手。
的index.php
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css"></link>
<script src="js/jquery-1.11.3.min.js"></script>
<script src="js/script.js"></script>
</head>
<body>
Welcome: <?php
// Start the session
session_start();
//Use session variable created in login.php
echo $_SESSION['username'];
?>
<div class="friend">
<?php
while($row = $res->fetch_assoc())
{
echo "<image class='img' src='images/" .$row['image'] . "'></image>";
echo "<div class='info'>";
echo $row['name'] . "<br>";
echo $row['surname'] . "<br>";
echo "SCORE: " . ($row['likes'] - $row['dislikes']);
echo "</div>";
}
?>
<div class='friend_actions'>
<image class='button' id='likes' src='images/like.jpg'></image><br>
<image class='button' id='dislikes' src='images/dislike.jpg'></image>
</div>
</body>
的script.js
$(document).ready(function () {
$('#likes').click(function() {
$.ajax({
url: 'likes.php',
type:'post',
data: {id: $('#id').val()},
success: function (result)
{
//Reload the current document
location.reload();
}
});
});
likes.php
<?php
require "php/conn.php";
$db->query("UPDATE friends_list SET likes = likes + 1 WHERE id = 1");
?>
答案 0 :(得分:0)
Here syntax error in script writing check
this your code
$(document).ready(function () {
$('#likes').click(function() {
$.ajax({
url: 'likes.php',
type:'post',
data: {id: $('#id').val()},
success: function (result)
{
//Reload the current document
location.reload();
}
}); //this end of ajax
}); //end of like event function
where is document end ?
you can not complete document '});' so complete document function