如何调试ajax响应? [英] How to debug ajax response?

查看:87
本文介绍了如何调试ajax响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我迷失了调试Ajax回调的方法。我正在尝试从php文件中打印响应,以查看呼叫是否正常运行,但未成功。当调用正常进行时,响应似乎返回空...控制台中什么都没有显示,但是网络选项卡中的响应为200 OK,我可以在响应头中看到数据。但是无法将其打印回控制台。 console.log(response)应该可以打印表格,但是可以。有什么其他调试方法?欢迎任何建议。

I am at lost with ways to debug my Ajax callback. I'm trying to print the response from the php file to see if the call is working but without success. While the call works, the response seem to return empty... Nothing shows in the console but the response in Network tab is 200 OK and I can see the data in the response header. However not able to print it back to the console. console.log(response) should print the table but meh. What are alternative ways to debug this? Any suggestion is welcome.

js

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

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

            });

所以这是我得到的证明,它可以在服务器端运行

So here's the proof I get that it is working server side

推荐答案

经过十分必要的深夜休息,我用了很多时间解决了这个问题头脑清晰。

After a much needed 10 hour break into the night, I solved the issue with a much clearer mind. I removed the dataType row and it worked for me.

听起来很愚蠢,PHP页面中的表不是JSON格式,所以当jQuery尝试

As silly as it may sound, the table in the PHP page was not in JSON format, so when jQuery tries to parse it as such, it fails.

希望它对您有帮助。如果不是,请在此处查看更多建议。

Hope it helps for you. If not, check out more suggestions 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
                    }

            });

这篇关于如何调试ajax响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆