I am trying to get a php variable from url using $_REQUEST to javascript so I can send it through Ajax.
At The top of my page I have:
<?php
  include_once('../php/connection.php');
  include_once('../php/getDiagnosis.php');
  $pid = $_REQUEST['pid'];
?>
And in the Java Script Part I have:
  <script src="../js/history.js"></script>
And in history.js:
var addHistory = function()
{
  var patient_medication = $("#patient_medicationn").val();
  var disease = $("#disease").val();
  var patient_side_effect = $("#patient_side_effect").val();
  var pid = '<?php echo $pid;?>';
  console.log(pid);
  if(disease=="select")
  {
    $("#disease").css('border-color', 'red');
    $("#disease").focus();
  }
  else
  {
    $.ajax({
      url: '../php/history.php',
      data: {pid: pid, patient_medication: patient_medication, disease: disease, patient_side_effect: patient_side_effect},
      type: 'POST',
      dataType: 'TEXT',
      success:function(resp)
      {
      },
      error:function(resp)
      {
        alert("Information have not been added, please try again");
      }
    })
  }
}
$(document).ready(function()
{
  $("#add_history").on('click', addHistory);
  $("#patient_medication").on('keypress', function(event)
  {
    if(event.which==13)
    {
        $("#add_history").click();
    }
  })
  $("#patient_side_effect").on('keypress', function(event)
  {
    if(event.which==13)
    {
        $("#add_history").click();
    }
  })
});
The result in the console is: