0

Upon sending an Ajax call to call a php file, I am getting an error on this file:

try {
    h.send(b.hasContent && b.data || null)
} catch (i) {
  if (c)
  throw i
}

This is the error I get:

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

I am sure that the php file I am calling has the correct address since it works on localhost.

Below is the ajax call I am using in jQuery to call the file:

$(document).ready(function(){

    $.ajax({
        url: 'functions/getParishes.php',
        type: 'get',
        dataType: 'json',
        success:function(response){
            var len = response.length;

            $('#parish-list').empty()

            for( var i = 0; i<len; i++){

                $("#parish-list").append("<option value='"+response[i]['ID']+"'>"+response[i]['Name']+"</option>");

            }
        }
    });
});

Can someone please shed a light on what I might be doing wrong?

Michele La Ferla
  • 6,775
  • 11
  • 53
  • 79
  • 1
    Problem with PHP code, not JS. Turn error logs to see what's wrong – Justinas May 22 '18 at 21:35
  • Check for PHP errors, use the network tab in your developer tools to see the response – Spoody May 22 '18 at 21:35
  • 1
    @Mehdi The error won't be in devtools, it will be in the log on the server. – Barmar May 22 '18 at 21:38
  • @Barmar _since it works on localhost_ I didn't read this part, he is having trouble in the production env. – Spoody May 22 '18 at 21:40
  • 500 errors tend to be the more annoying since you cannot just spill them in the browser in anyway. You have to make sure php is set to log them to a server logfile (as Barmar mentioned). But yeah, this has nothing to do with JS nor AJAX. – IncredibleHat May 22 '18 at 21:40
  • That php code snippet in the question, isn't valid php as it is. So we really cannot pinpoint the actual cause of your 500 error. – IncredibleHat May 22 '18 at 21:41
  • Ok I'll try and check the error through postman maybe I can get a clearer indication of what might have gone wrong. – Michele La Ferla May 22 '18 at 22:12

0 Answers0