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

42,133

Solution 1

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.

Solution 2

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.

Share:
42,133
Abs
Author by

Abs

Updated on July 24, 2020

Comments

  • Abs
    Abs almost 4 years

    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
    
  • Syntax
    Syntax over 15 years
    Some crappy hosts running php4/php5 side by side on the same domain are using .php as php4 and .php5 for php5. It's ghetto lol.
  • Abs
    Abs over 15 years
    My old host told me to rename php scripts to PHP5 if i wanted to make use of PHP version 5 since I needed Exceptions. This is normal. It worked perfectly on the other server but on this server it doesn't! It does have PHP 5.2.6 installed.
  • Abs
    Abs over 15 years
    lol ghetto...btw...its got nothing to do with crappy hosts. This one is very reputable it just took them time to switch from 4 to 5.
  • Abs
    Abs over 15 years
    I get returned a blank page - what does that mean? I make previous AJAX calls and they go the same server but this one just returns a 500?? What could it possibly be?
  • Syntax
    Syntax over 15 years
    Abs, as luca has stated your logs should reveal the problem. There are logs for apache and logs for php depending on your setup. Review both, you may have be overlooking something.
  • Syntax
    Syntax over 15 years
    Generally hosts allow 1 or the other. Running them side by side can cause side affects when people try to intermix the two. Say require('mypage.php'); inside of myOtherPage.php5 - it is ghetto :) not trying to diss your host.