[英]Why is the ajax function not executing when I click on the 'like' image?
I have a picture of a like button, when clicked, should update the score by 1. I am using ajax to execute this. 我有一个喜欢按钮的图片,单击该按钮后应将分数更新1。我正在使用Ajax执行此操作。 However, when I click the image nothing happens.
但是,当我单击图像时,没有任何反应。 When I hover my mouse on the image, the pointer does not even change to a hand.
当我将鼠标悬停在图像上时,指针甚至不会变为手。
index.php 的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 的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 likes.php
<?php
require "php/conn.php";
$db->query("UPDATE friends_list SET likes = likes + 1 WHERE id = 1");
?>
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.