如何调试 ajax 响应?

How to debug ajax response?

我不知道如何调试我的 Ajax 回调。我正在尝试打印来自 php 文件的响应,以查看调用是否正常但没有成功。虽然调用有效,但响应似乎 return 为空...控制台中没有显示任何内容,但“网络”选项卡中的响应为 200 OK,我可以在响应 header 中看到数据。但是无法将其打印回控制台。 console.log(response) 应该打印 table 但是嗯。调试这个的替代方法是什么?欢迎任何建议。

js

   $.ajax({
                    type: 'POST',
                    dataType : 'json',
                    url: 'queries/getsocial.php',
                    data:nvalues,
                    success: function(response)
                    {

                        console.log(response);//does not print in the console
                    }

            });

所以这是我得到的证明它在服务器端工作的证据

你能加一张控制台的照片吗?当类似的事情发生在我身上时,我通常会打印一些东西 console.log(“Response:”+ response)。至少如果你看到了文本,你至少可以确定你的函数正在执行。

经过急需的 10 个小时的深夜休息后,我以更清晰的思路解决了这个问题。我删除了 dataType 行,它对我有用。

虽然听起来很愚蠢,但 PHP 页面中的 table 并不是 JSON 格式,因此当 jQuery 尝试这样解析它时,它失败了。

希望对你有所帮助。如果没有,请查看更多建议 here.

之前

  $.ajax({
                    type: 'POST',
                    dataType : 'json',
                    url: 'queries/getsocial.php',
                    data:nvalues,
                    success: function(response)
                    {

                        console.log(response);//does not print in the console
                    }

            });

之后(现在有效)

  $.ajax({
                    type: 'POST',
                    url: 'queries/getsocial.php',
                    data:nvalues,
                    success: function(response)
                    {

                        console.log(response);//yes prints in the console
                    }

            });