How to debug ajax response?
Asked Answered
W

2

0

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 enter image description here

Waltraudwaltz answered 20/6, 2018 at 1:57 Comment(0)
W
2

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.

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.

Before

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

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

            });

After (Works now)

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

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

            });
Waltraudwaltz answered 20/6, 2018 at 18:16 Comment(0)
S
0

Can you add a photo of the console? When something like that happens to me, I usually print something console.log(“Response: “+ response). At least if you see the text at least you can be sure your function is getting executed.

Sanalda answered 20/6, 2018 at 2:19 Comment(1)
Thanks Jhonny. I was able to solve the problem. See my answer. Cheers.Waltraudwaltz

© 2022 - 2024 — McMap. All rights reserved.