Getting php in JS [duplicate]

ok, i am trying to have JavaScript code that calls for a PHP function so far i have this

PHP:

function loadMSG() {
  ob_end_clean();
  $MSG = fopen("MSG.txt", "r");
  echo fread($MSG, filesize("MSG.txt"));
  fclose($MSG);
}

// Reload MSG
function reloadMSG() {
  if (in_array(filemtime("MSG.txt"), range(time() - 30, time() + 30))) {
    loadMSG();
  } else {
    sleep(3);
  
  }
}

it works on it’s own so there’s no problem there it’s just i need it to be called by JS. i have seen many other people give answers to similar questions but they aren’t very explanatory and all use jquery which i don’t understand much.