我有问题,Jquery Post没有将数据发送到其他页面。通过单击图像将数据发送到LikeMail.php页面。日期存储在图像的ID中。
<a href="viewProfile.php?id=<?php echo $record['user_id']; ?>"><img class="img-rounded" id="<?php echo $record['user_id']; ?>" src=" <?php echo "../shadi/images/" . $record['user_photo1'] ?>" alt=""
width="70%" height="20%"> </a>
这是我的LikeMail.php页面
<?php
session_start();
?>
<html>
<head>
<script src="jquery-1.12.2.min.js"></script>
<script src="test.js"></script>
</head>
</html>
<?php
include("db.php");
if(!isset($_SESSION['login'])) {
echo "";
}
else {
$user1 = $_SESSION['user_id'];
// echo $user1;
if(isset($_POST['fname'])) {//This is being received from jquery
$user2 = $_POST['fname'];
//$lname = $_POST['surname'];
//echo $lname;
/*$sql = "UPDATE notification SET alert='$fname' WHERE id = '1'";
if(mysqli_query($conn,$sql))
echo "updated";*/
$check_for_likes = mysqli_query($conn, "SELECT * FROM liked WHERE user1='$user1' AND user2='$user2'");
$numrows_likes = mysqli_num_rows($check_for_likes);
if (false == $numrows_likes) {
echo mysqli_error($conn);
}
if ($numrows_likes >= 1) {
echo '<input type="submit" name="unlikebutton_' . '" value="Unlike" id="Unlike" class="btn btn-lg btn-info edit">';
}
if ($numrows_likes == 0) {
echo '<input type="submit" name="likebutton_' . '" value="Like" id="Like" class="btn btn-lg btn-info edit">';
}
}
}?>
正在从上一页收到带变量fname
的POST数组(在代码中的注释中也会提到)。
这是jquery方法
$(document).ready(function(){
$('.img-rounded').click(function(){
$.post("LikeMail.php",
{fname: this.id},
function(data){
$('.respond').html(data);
}
);
});
});
你能告诉我那里有什么错误。我已经在 LikeMail.php 之外的其他页面上运行了这个jquery方法,它运行得很好,但是Jquery的帖子没有将数据发送到 LikeMail.php
答案 0 :(得分:1)
尝试在<a>
点击时发生prevent default behavior,可能以阻止事件传播。
$('.img-rounded').click(function(e){
e.stopPropagation(); // not sure if needed
e.preventDefault();
$.post("LikeMail.php",
{fname: this.id},
function(data){
$('.respond').html(data);
}
);
});
答案 1 :(得分:1)