Search code examples
phpjavascriptajaxerror-handlinginternal

How to obtain more information from Ajax call to PHP file failure?


I moved my website on a server in order to go live, but I am getting an issue with an Ajax call to a PHP file designed to return a text value. I am trying to find what the bug is. The code works on my local PC.

The error I get from the Ajax call is:

Error: error Internal Server Error

I am using the following piece of code to perform the call:

function goClick(ttype, vvalue) {

    $.get(fw_script, { type: ttype, value: vvalue, langpref: langpref })
        .success(function(result) {
            setResult(result);
        })
        .error(function(jqXHR, textStatus, errorThrown) {
            setResult("Error: " + textStatus + " " + errorThrown);
            alert("Failure");
        });

}

How can I obtain more information about what could cause this issue? I am not an expert at PHP. Is there some equivalent of Java's try {} catch {} finally{} in PHP? Would this be the proper way to catch exceptional errors on the server side? Should I wrap my PHP code with a catch? How to retrieve information about internal errors?


Solution

  • You're exactly right. try {} catch {} works the same way in PHP. http://php.net/manual/en/language.exceptions.php

    Internal Server Errors are often caused by a typo or similar in the PHP file. You can try to enable error logging to get more details about the error.