简体   繁体   中英

Debugging PHP during a jQuery.getJSON request

I'm trying to debug some PHP that is called from a jQuery.getJSON request. Everything works on my local machine and one other server but I am having trouble getting it to work on my new server.

I have boiled it down to the following lines:

define('WP_USE_THEMES', false);
require_once('../../../../wp-load.php');

$url = 'http://findyourmp.parliament.uk/api/search?q='.$_GET['q'].'&f=json';
$feed = file_get_contents($url);

Is there anyway I can see which one of these is failing? How would I output these variables without the PHP files sending a response back to the initial jQuery call?

It's all a bit confusing as it works fine on my local machine and other server..

Thanks

Troubleshooting AJAX PHP scripts can sometimes be a hassle! The easiest way would be to see what the console is showing as RESPONSE HEADERS in the XHR section. That doesn't always apply, however.

One thing I've been doing is writing a small script that I can use independently of the rest of the application. Something like this:

<?
require( ................. ); // make sure you include all files you need for the ajax script
error_reporting(ALL);
ini_set('display_errors',1);
include('my.ajax.script.php'); // the AJAX script in question goes here
?>

Save that on your server as ajxchecker.php and you can call it anytime for a quick response.

Use FireFox. Install the FireBug extension and then install FirePHP.

http://getfirebug.com/
http://www.firephp.org/

You will then be able to fully debug your php code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM