1

On local host all my ajax calls are working perfectly, but as soon as i uploaded my website online ajax call is returning a 500 internal server error

i tried to change the url in my js file but it didn't work

this is my js code

function getCode() {
  $.ajax({
    type: "GET",
    url: "/ajax.php",
    data: "fn=getCode",
    dataType: "html",
    async: true,
    success: function(msg) {
      msg = msg.split(" - ");
      //console.log(msg[1]);

      if (msg[0] === "success") {
        document.getElementById("hiddencode").value = msg[1];
        alert(msg[1]);
      }

      if (msg[0] === "error") {
        alert("Unable to get Code try again!");
      }
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {
      //console.log("Unable to connect to Ajax file");
      console.log(errorThrown);
    }
  });
}

this is my ajax.php code

if (isset($_GET['fn'])) {
    if ($_GET['fn'] === "getCode") {
        $generated_code = getCode();
        echo "success - " . $generated_code;
    } else {
        echo 'error - ';
    }
}
function getCode()
{
    return rand(1000, 9999);
}
if (isset($_GET['fun'])) {
    if ($_GET['fun'] === 'updateListName') {
        updateListName();
    }
}

this is the error code in the inspector

jquery.min.js:2 GET http://listapp.xyz/ajax.php?fn=getCode 500 (Internal Server Error)
send @ jquery.min.js:2
ajax @ jquery.min.js:2
getCode @ script.js:74
onclick @ forgot-pass.php:66
script.js:95 Internal Server Error

Any help would be appreciated thanks in advance

  • no that's not my problem, on localhost it's working perfectly – Joe Estephan Jun 08 '19 at 16:47
  • The 500 server error is due to a server-side issue. You should then provide a better context of the code inside the PHP file you are calling. – k3llydev Jun 08 '19 at 16:47
  • i provided my ajax.php code this is the file that i am calling' – Joe Estephan Jun 08 '19 at 16:48
  • `updateListName()` function is missing. – k3llydev Jun 08 '19 at 16:49
  • If I were you I would comment out the current `php` source code and do a simple `echo 'php page working';` and then start to un-comment the php in sections to check where the issue is. When you have a problem you cannot identify it is always best to cut the source code into sections to debug each part before throwing it all together again. – NewToJS Jun 08 '19 at 16:49

0 Answers0