如何从间接页面获取jquery POST请求?

时间:2016-08-19 16:48:03

标签: javascript php jquery ajax

我一直致力于使用jQuery,AJAX和PHP的Like and Different功能。我从间接页面获取jQuery post请求。例如,我有2个PHP页面,import tkinter as tk root = tk.Tk() tk.Label(root, text = "This is the main window").pack() sub_window = tk.Toplevel(root) tk.Label(sub_window, text = "This is the other window").pack() root.mainloop() viewProfile.phpLikeMail.php中的AJAX函数正在调用LikeMail.php

这是viewProfile.php页面描述的部分

viewProfile.php

以下是这个AJAX函数实际来自 ----------------- | Like/Unlike | ----------------- 的按钮:

LikeMail.php

HTML:

function like()
{
    var req  = new XMLHttpRequest();
    req.onreadystatechange = function()

    {
        if(req.readyState==4 && req.status==200)
        {
            document.getElementById('like1').innerHTML=req.responseText;

        }
    }
    req.open('POST','LikeMail.php','true');
    req.send();
}
setInterval(function(){like()},1000);

<div id="like1"></div> 中显示的是输出。 以上按钮可以是divLike取决于Unlike中的条件,这将在LikeMail.php说明部分中进行说明。

当其中一个(按钮)LikeMail.phpLike被点击时。然后它调用相应的jQuery点击功能,将发布请求发送到Unlike。我在标题中提到了LikeMail.php页面,因为IndirectLike按钮实际存在于Unlike中页。但由于AJAX调用,这些按钮显示在LikeMail.php页面中。然后,我通过viewProfile.php将帖子请求发送到实际页面viewProfile.php

这是LikeMail.php按钮的帖子

Unlike

这是jQuery帖子或$(document).ready(function(){ $('#Unlike').unbind().click(function(){ $.post("LikeMail.php", {Unlike: this.id}, function(data){ $('#response').html(data); } ); }); }); 按钮

Like


$(document).ready(function(){ $('#Like').unbind().click(function(){ $.post("LikeMail.php", {Like: this.id}, function(data){ $('#response').html(data); } ); }); }); 页面的描述部分


以下是LikeMail.php页面描述的部分

viewProfile.php页面中显示的{p> LikeUnlike按钮取决于此代码:

viewProfile.php

按钮取决于上述两个条件
现在,当点击$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="Unlike" value="Unlike" id="Unlike" class="btn btn-lg btn-info edit">'; } elseif ($numrows_likes == 0) { echo '<input type="submit" name="Like" value="Like" id="Like" class="btn btn-lg btn-info edit">'; } 按钮时,来自Like的帖子请求就会显示在此处。

viewProfile.php

同样点击if(isset($_POST['Like'])) //When Like button in viewProfile.php is clicked then this peace of code inside if condition should run and insert some record in database { $total_likes = $total_likes+1; $like = mysqli_query($conn, "UPDATE user SET user_Likes = '$total_likes' WHERE user_id = '$user2'"); $user_likes = mysqli_query($conn, "INSERT INTO liked (user1,user2) VALUES ('$user1','$user2')"); $query3 = "INSERT INTO notification (user1, user2, alert, notificationType) VALUE ('$user1','$user2','unchecked','like')"; if (mysqli_query($conn, $query3)) { echo "Like"; } else { echo mysqli_error($conn); } } 按钮时。这种代码的和平应该运行。

Unlike

问题:

主要问题是jQuery帖子请求未从if(isset($_POST['Unlike'])) //This is the condition for Unlike button. It should delete record from databse { $total_likes = $total_likes-2; $like = mysqli_query($conn, "UPDATE user SET user_Likes='$total_likes' WHERE user_id='$user2'"); $remove_user = mysqli_query($conn, "DELETE FROM liked WHERE user1='$user1' AND user2='$user2'"); $query3 = "DELETE FROM notification WHERE user1='$user1' AND user2='$user2' AND notificationType='like'"; $check = mysqli_query($conn, $query3); if ($check) { echo "Unlike"; } else { echo mysqli_error($conn); } } 发送到viewProfile.php。有没有办法从间接页面发送jQuery post请求?

0 个答案:

没有答案