Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ajax

php

apache

I make an AJAX request like so using JQuery:

$.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:

$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 except on 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.

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/

I hid my IP. At that line:

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.

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.

yum install php-xml
yum install php-xmlrpc
like image 801
Abs Avatar asked Feb 11 '09 19:02

Abs


People also ask

What is 500 Internal server error Ajax?

The 500 Internal Server Error is a very general HTTP status code. It means something has gone wrong on the website and webserver is unable to specify what exactly, thus failing in fulfilling the request made by the client.

How do I fix a 500 Internal server error?

Clear your browser cache and cookies Check these articles on deleting the cache on an Android phone or iPhone, if you use a mobile device. Alternatively, you can test opening the page from another browser. For instance, if you use Chrome, try Firefox or vice versa.

What causes 500 errors PHP?

PHP Coding Timing Out If your PHP script makes external network connections, the connections may time out. If too many connections are attempted and time out, this will cause a "500 Internal Server Error." To prevent these time outs and errors, you'll want to make sure that PHP scripts be coded with some timeout rules.


2 Answers

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.

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.

like image 189
Syntax Avatar answered Sep 20 '22 04:09

Syntax


What? .php5 ? I don't know your apache configuration (given you're even using it), but .php will work for all versions of 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.

like image 23
Luca Matteis Avatar answered Sep 23 '22 04:09

Luca Matteis