从php文件接收jQueryAjax的空响应

从php文件接收jQueryAjax的空响应,php,jquery,ajax,Php,Jquery,Ajax,我正在用PHPjQuery和Ajax制作一个评论回复系统。到目前为止,我成功地使用php和jQueryAjax进行了评论和回复评论操作。当我回复一条评论时,我从jqueryajax收到回复评论的数量,并在屏幕上打印该数量。现在我接下来要做的是在提交回复后将其打印到屏幕上。我创建了jQueryAjax函数并编写了php脚本。然后,我将从php格式化的$output返回到ajax。问题是我收到的是空白响应,但我直接测试了php文件,它工作正常,并将$output变量输出到屏幕。请帮忙。下面是我负责输

我正在用PHPjQuery和Ajax制作一个评论回复系统。到目前为止,我成功地使用php和jQueryAjax进行了评论和回复评论操作。当我回复一条评论时,我从jqueryajax收到回复评论的数量,并在屏幕上打印该数量。现在我接下来要做的是在提交回复后将其打印到屏幕上。我创建了jQueryAjax函数并编写了php脚本。然后,我将从php格式化的$output返回到ajax。问题是我收到的是空白响应,但我直接测试了php文件,它工作正常,并将$output变量输出到屏幕。请帮忙。下面是我负责输出回复的ajax部分:

  <script type="text/javascript">
    load_replies();
    function load_replies() {
     $.ajax({
     url: "widgets/board_reply_fetch.php?comment_id=<?php echo 
$board_comment_id_number;?>",
            method: "POST",
            success: function(data){
                $("#reply_comment").html(data);
                console.log(data);
            }
        });
    }
</script>

加载_回复();
函数加载_回复(){
$.ajax({
url:“widgets/board_reply_fetch.php?comment_id=”,
方法:“张贴”,
成功:功能(数据){
$(“#回复#评论”).html(数据);
控制台日志(数据);
}
});
}
这是我的php文件:

<?php 
require_once '../includes/session.php';
require_once '../includes/functions.php';
require_once '../includes/validation_functions.php';

if (isset($_GET["comment_id"])) { 
$comment_id = (int)$_GET["comment_id"];

$reply_data = find_board_replies_by_comment_id($comment_id);

$output = "";
$output_array = array();
while ($reply_assoc = mysqli_fetch_assoc($reply_data)) {
    $reply_comment_id = $reply_assoc['comment_id'];
    $reply_board_id = $reply_assoc['board_id'];
    $reply_user_id = $reply_assoc['user_id'];
    $reply_text = $reply_assoc['reply'];
    $reply_timestamp = $reply_assoc['reply_timestamp'];

    $reply_user_data = find_user_data_by_id($reply_user_id);


    $profile_image = $reply_user_data['profile_picture']; 
    $profile_image_thumb = "../uploaded_pictures/profile/$reply_user_id/" . $reply_user_id . "small.png";

    if ($profile_image == "") {
        if ($comment_user_data['gender'] == "Male"){
            $user_profile_picture = "../images/ProfilePicMale.png";
        } else {
            $user_profile_picture = "../images/ProfilePicFemale.png";
        }
    } else {
        $user_profile_picture = $profile_image_thumb;
    }

    $full_name = ucfirst(htmlentities($reply_user_data['first_name'])) . " " . ucfirst(htmlentities($reply_user_data['last_name']));
    $time_of_post = time_of_post($reply_timestamp);
    $the_reply_text = nl2br($reply_text);

    $output = "<div class=\"reply_comment_div\">";
    $output .= "<a href=\"profile.php?user_id=$reply_user_id\" class=\"board_comments_div_picture\">";
    $output .= "<img src=\"$user_profile_picture\" width=\"50px\" height=\"50px\" /></a>";
    $output .= "<a href=\"profile.php?user_id=$reply_user_id\" class=\"board_comments_reply_link\">$full_name</a>";
    if ($reply_user_id == $_SESSION['user_id']){ 
        $output .= "<a href=\"edit_comment_board.php?comment_id=$reply_comment_id\" class=\"edit_comment_button_board\">Edit</a>";
        $output .= "<a href=\"widgets/delete_board_comment.php?board_id=$reply_board_id&comment_id=$reply_comment_id\" onclick=\"return confirm('Are you sure you want to delete this admin?')\" class=\"delete_button_status\">Delete</a>";
    }
    $output .= "<div class=\"board_comment_submited_on\">submitted $time_of_post</div>";
    $output .= "<span class=\"comment_content_span\">$the_reply_text</span>";
    $output .= "</div>";

    $output_array[] = $output;
}
foreach ($output_array as $array) {
    echo $array;
}
}

尝试将发送到php页面的数据存储在数据对象中

示例:


加载_回复();
函数加载_回复(){
var commment_id=“”;
$.ajax({
url:“widgets/board\u reply\u fetch.php”,
数据:{commentId:commment\u id},//commment\u id将其存储在此处
方法:“获取”,
成功:功能(数据){
$(“#回复#评论”).html(数据);
控制台日志(数据);
}
});
}
使用POST方法:

if (isset($_POST["comment_id"])) { 
$comment_id = (int)$_POST["comment_id"];

首先检查浏览器开发工具网络中的实际请求。看看响应体在那里是什么样子。另外,请确保url是正确的,因为您在Ajax中使用POST方法,但在php文件中使用GET
if(isset($\u-GET[“comment\u-id”]){$comment\u-id=(int)$\u-GET[“comment\u-id”]
我检查了它,这就是为什么我知道它提供了一个空数据@Rahul,我尝试了这两种方法,但什么也没有:/但是现在POST/GET不匹配请将POST与GET放在一起,因为在php页面中,您使用的是GET方法。应该在回答中解释一下,但是当我没有任何表单时,我可以这样做吗?我在ajax中添加了数据行,并将php文件更改为$\u POST但是现在我在测试php文件时没有得到任何结果alone@NevilSaul Blemuss我以前更改过它,但它也不起作用:/如果OP没有更改ajax请求,将不会设置,因为他们正在使用url GET Param什么更改?@charlietfloh是的,没有确切的数据。尽管OP没有出现,但你可以在帖子上设置$GET paramsar需要发布他们仍然可以访问$_GET[“comment\u id”]。`是的,是的,为什么不发布一个合适的答案!@charlietfl
if (isset($_POST["comment_id"])) { 
$comment_id = (int)$_POST["comment_id"];