简体   繁体   English

在jQuery.getJSON请求期间调试PHP

[英]Debugging PHP during a jQuery.getJSON request

I'm trying to debug some PHP that is called from a jQuery.getJSON request. 我正在尝试调试一些从jQuery.getJSON请求调用的PHP。 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? 在没有PHP文件将响应发送回初始jQuery调用的情况下,如何输出这些变量?

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! 对AJAX PHP脚本进行故障排除有时会很麻烦! The easiest way would be to see what the console is showing as RESPONSE HEADERS in the XHR section. 最简单的方法是查看控制台在XHR部分中显示为RESPONSE HEADERS的内容。 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. 将其另存为ajxchecker.php在服务器上,您可以随时调用它以快速响应。

Use FireFox. 使用FireFox。 Install the FireBug extension and then install FirePHP. 安装FireBug扩展,然后安装FirePHP。

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

You will then be able to fully debug your php code. 然后,您将能够完全调试您的php代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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