Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to debug data when using json / ajax

Tags:

json

ajax

php

I have created a php page that displays some records from my db.
I also have a button that executes some ajax to update the records, and then show the new / updated dataset on the same page. I'm having problems with my ajax call and I'd like some tips on how to troubleshoot. I've noticed that since my header has been explicitly set to be json content, i can't just do things like var_dump from the controller to see the data BEFORE it is sent to the view. Unfortunately, for some reason, my console.log calls in the ajax method are not working for me either. i don't know why.

But I'm wondering if someone can tell me other ways to debug my code. I know I can change the json data type to html / text and then remove all code in my controller that sets headers / calls json_encode... but just in case there's a better way, I thought I'd ask.

like image 775
dot Avatar asked Dec 17 '12 18:12

dot


1 Answers

You can use the Developer console in Chrome, click on the Network tab, and then at the bottom you can limit the type to "XHR" then you can try to make the AJAX request, and you should see everything there is to see about it, including the response, etc.

like image 123
SSH This Avatar answered Oct 05 '22 23:10

SSH This