AJAX 调用 PHP 脚本给我 500 内部服务器错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/538391/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 23:01:40  来源:igfitidea点击:

AJAX Call to PHP script gives me 500 Internal Server Error?

phpajaxapache

提问by Abs

I make an AJAX request like so using JQuery:

我使用 JQuery 像这样发出 AJAX 请求:

$.ajax({
  type: "GET",
  url: "getvideo.php",
  data: 'videoid=' + vid,

I use firebug to tell me what's going on and it tells me that a 500 internal server error has occurred? Here is part of the script concerned:

我使用 firebug 来告诉我发生了什么,它告诉我发生了 500 内部服务器错误?这是相关脚本的一部分:

$videoid = $_GET['videoid'];
$get = new youtubeAPI();
$get->getVideoAPI($videoid);

class youtubeAPI extends Exception {

  function getVideoAPI($videoid){

    if (isset($videoid)) {

      $clientLibraryPath = 'library';
      $oldPath = set_include_path(
        get_include_path() . PATH_SEPARATOR . $clientLibraryPath
      );

      require_once 'Zend/Loader.php'; // the Zend dir must be in your include_path

I use the same AJAX call to other scripts and they are fine. I have used these scripts on another server and it was fine excepton the other server the file is named "getvideo.php5" whereas here I named it "getvideo.php" since I have PHP 5.2.6 installed only.

我对其他脚本使用相同的 AJAX 调用,它们很好。我在另一台服务器上使用过这些脚本,除了在另一台服务器上文件被命名为“getvideo.php5”外,这里我将它命名为“getvideo.php”,因为我只安装了 PHP 5.2.6。

Please help

请帮忙

UPDATE

更新

This is the error:

这是错误:

[Wed Feb 11 20:48:17 2009] [error] [client xx.xx.xxx.xxx] PHP Fatal error: Class 'DOMDocument' not found in /var/www/html/library/Zend/Gdata/App.php on line 734, referer: http://xx.xx.xx.xxx/

[2009 年 2 月 11 日星期三 20:48:17] [错误] [客户端 xx.xx.xxx.xxx] PHP 致命错误:在 /var/www/html/library/Zend/Gdata/App 中找不到“DOMDocument”类。 php 734 行,引用:http: //xx.xx.xx.xxx/

I hid my IP. At that line:

我隐藏了我的IP。在该行:

public static function importString($string, $className='Zend_Gdata_App_Feed') {
  // Load the feed as an XML DOMDocument object
  @ini_set('track_errors', 1);
  $doc = new DOMDocument(); // LINE 734
  $success = @$doc->loadXML($string);
  @ini_restore('track_errors');

But I shouldn't be playing around with that right? In any case, that class doesn't exist as a script and doesn't exist in that script as a class. I AM MAKING USE OF THIS SAME LIBRARY IN MY OTHER SERVER. It is also missing that too??? This is what I downloaded from the Youtube API zip folder.

但我不应该玩弄那个吧?在任何情况下,该类都不作为脚本存在,也不作为类存在于该脚本中。我正在我的其他服务器上使用同一个库。它也缺少那个???这是我从 Youtube API zip 文件夹下载的内容。

SOLVED

解决了

This was a brand new server and it had minimal PHP installed. I was missing PHP dom functions. A quick install fixed this problem. Thanks for reminding me to look at the logs. I should have tried that first.

这是一个全新的服务器,它安装了最少的 PHP。我缺少 PHP dom 函数。快速安装解决了这个问题。感谢您提醒我查看日志。我应该先尝试的。

yum install php-xml
yum install php-xmlrpc

回答by Syntax

Try executing the call manually yourself in your browser (its the same thing) and see what gets returned. If nothing gets returned and you get a 500 internal server error, you need to then review your logs and see whats causing this error to happen.

尝试在浏览器中自己手动执行调用(它是一样的)并查看返回的内容。如果没有返回任何内容并且您收到 500 内部服务器错误,则您需要查看日志并查看导致此错误发生的原因。

Also make sure you are making the ajax call to the proper domain. If you try calling out of your domain the call will fail every time.

还要确保您正在对正确的域进行 ajax 调用。如果您尝试呼出您的域,则每次呼叫都会失败。

回答by Luca Matteis

What? .php5? I don't know your apache configuration (given you're even using it), but .phpwill work for all versions of PHP.

什么?.php5? 我不知道您的 apache 配置(假设您正在使用它),但.php适用于所有版本的 PHP。

Anyway, try to directly access that URL and see what happens, this shouldn't have anything to do with Ajax. Also take a look at your web-server logs.

无论如何,尝试直接访问该 URL 并查看会发生什么,这应该与 Ajax 没有任何关系。另请查看您的网络服务器日志。

回答by Jacob

Make sure permissions are set correctly. Just had the same problem on a justhost.com server Set permissions on my php script to 0644 and all is well.

确保权限设置正确。刚刚在 justhost.com 服务器上遇到了同样的问题将我的 php 脚本的权限设置为 0644,一切都很好。

回答by marquito

I had a similar problem, but the solution was different. Check to see if you have uploaded all files referenced in the PHP code. I found out the file I was calling through ajax had references to classes whose definition files were missing, and the server returned a 500 Internal server errorfor that.

我遇到了类似的问题,但解决方案不同。检查您是否已上传 PHP 代码中引用的所有文件。我发现我通过 ajax 调用的文件引用了定义文件丢失的类,服务器500 Internal server error为此返回了一个。

回答by Amine Mostefaoui

probably you just have a php code error copyand pastthe (url)
And will show you the error fix it and all should be okay good luck

也许你只是有一个PHP代码错误copy,并past(url)
并会告诉你的错误修复它,都应该是好的运气好