ฉันกำลังพยายามรับตัวแปร php จาก url โดยใช้ $_REQUEST
ถึง javascript เพื่อที่ฉันจะได้ส่งผ่าน Ajax ได้
ที่ด้านบนของหน้าฉันมี:
<?php
include_once('../php/connection.php');
include_once('../php/getDiagnosis.php');
$pid = $_REQUEST['pid'];
?>
และในส่วน Java Script ฉันมี:
<script src="../js/history.js"></script>
และใน 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();
}
})
});
ผลลัพธ์ในคอนโซลคือ: