duanli0453 2018-07-18 19:24
浏览 113
已采纳

jquery到php发布500内部服务器错误.load

I was googling for a few hours but I'm still stucked with this. I'm trying to send data to a php file with .load jquery function. I'm trying this:

$(document).ready(function() {
        var commentCount = 2;
        $("button").click(function() {
            commentCount = commentCount + 2;
            console.log("Coment Count: " + commentCount);
            $("#comments").load("load-comments.php", {
                'commentNewCount': commentCount
            });
        });
    });

And my php should receive this variable as POST so I can get the information from a MySQL call.

$commentsNewCount = $_POST['commentNewCount'];
$more_comments->bindParam(':limits', $commentsNewCount, PDO::PARAM_INT);
$more_comments->execute();
$more_all_comments = $more_comments->fetchAll();
foreach ($more_all_comments as $key => $rs) {
    echo '<p>';
    echo $rs['author'];
    echo '<br>';
    echo $rs['message'];
    echo '</p>';
}

I checked the console from the developer tool and I get the following error:

POST http://my_url/load-comments.php 500 (Internal Server Error)

I already try to implement a try catch in the .load function but I wasn't be able to get the error message, I printed several console.log as a mode for debugging but I don't know what could be the error.

This is for printing in real time, searched in google but can't find something like this, a lot of people use more complex functions like $.ajax or something like so I'm guessing my error is very simple.

Please, help me with your wisdom.

  • 写回答

3条回答 默认 最新

  • doucigua0278 2018-07-18 19:53
    关注

    You can pass data with load(), I think that the error is in the server side, you should check, debug or use var_dump in php and maybe you can use postman and send a post request with the param commentNewCount in the body. ref: http://api.jquery.com/load/

    The load() method send a GET request if you only pass the url, but if you pass a params object it send a POST request, check https://github.com/jquery/jquery/blob/3d732cca6b5076a9d13eee98e2b075b37384cd91/src/ajax/load.js#L34

    For example:

    $( '#comments' ).load( 'load-comments.php', 
      { commentNewCount: commentCount },
      function() {
        console.log('server return');
      }
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥15 在现有系统基础上增加功能