首先是应用程序的工作原理:(注意:页面上有多个用户,例如 Patient M、Patient E 等)
1) 患者 X 的姓名旁边是一个标记为Check In的按钮。这是在服务器端记录的。
2) 单击Check In按钮后,用户会看到一个下拉菜单(替换初始按钮),其中包含用户可以选择的多个位置。从选择中选择位置后,服务器端将再次更新。
3)然后用户可能决定选择多个位置,重复步骤 2
4) 最后,当用户选择完位置后,他在用户在步骤 2 和 3 中单击位置的同一个选择中单击Check Out 按钮,标题为 Check Out。单击此按钮后,它将被发送到 checkloc.php 并记录。
5) 最后,下拉菜单消失,出现 Checked Out 字样。
不幸的是,问题在于,如果我现在是计算机 1,并且通过单击签入、选择位置和签出的过程,这与计算机 2 完全不同。
来一张图:
所以基本上我需要一种方法来每隔几秒钟抓取一次服务器代码并用当前值更新表单元素。我是一个相当新的程序员,所以代码和教程会更有帮助。另外,就像我刚才提到的,我是一名新程序员,所以如果我的代码可以以任何方式清理,那就太好了。
感谢您的任何帮助!我很高兴澄清您的任何问题!
继承人的代码:
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.locationSelect').hide(); // Hide all Selects on screen
$('.finished').hide(); // Hide all checked Out divs on screen
$('.checkOut').hide();
$('.checkIn').click(function() {
var $e = $(this);
var data = $e.data("param").split('_')[1] ;
// gets the id of button
// You can map this to the corresponding button in database...
$.ajax({
type: "POST",
url: "checkin.php",
// Data used to set the values in Database
data: { "checkIn" : $(this).val(), "buttonId" : data},
success: function() {
// Hide the current Button clicked
$e.hide();
// Get the immediate form for the button
// find the select inside it and show...
$('.locationSelect').show();
$('.checkOut').show();
}
});
});
$('.locationSelect').change(function() {
$e = $(this);
var data = $e.data("param").split('_')[1] ;
// gets the id of select
// You can map this to the corresponding select in database...
$.ajax({
type: "POST",
url: "changeloc.php",
data: { "locationSelect" : $(this).val(), "selectid" : data},
success: function() {
// Do something here
}
});
});
$('.checkOut').click(function() {
var $e = $(this);
var data = $e.data("param").split('_')[1] ;
// gets the id of button
// You can map this to the corresponding button in database...
$.ajax({
type: "POST",
url: "checkout.php",
// Data used to set the values in Database
data: { "checkOut" : $(this).val(), "buttonId" : data},
success: function() {
// Hide the current Button clicked
$e.hide();
$('.locationSelect').hide();
// Get the immediate form for the button
// find the select inside it and show...
$('.finished').show();
}
});
});
});
</script>
和html:
<button class="checkIn" data-param="button_9A6D43BE-D976-11D3-B046-00C04F49F230">Check In</button>
<form method='post' class='myForm' action=''>
<select name='locationSelect' class='locationSelect' data-param="location_9A6D43BE-D976-11D3-B046-00C04F49F230">
<option value="0">Select a location</option>
<option value='1'>Exam Room 1</option>
<option value='2'>Exam Room 2</option>
<option value='3'>Exam Room 3</option>
<option value='4'>Exam Room 4</option>
</select>
</form>
<button class="checkOut" data-param="cbutton_9A6D43BE-D976-11D3-B046-00C04F49F230">Check Out</button>
<div class='finished' style='color:#ff0000;'>Checked Out</div>
继承人服务器端代码(我把它分成三页只是为了测试)
签入.php
<?php
date_default_timezone_set('America/Denver');
$apptid = $_REQUEST['buttonId'];
$currentlocationstart = date("Y-m-d H:i:s");
if(isset($_REQUEST['checkIn'])){
$checkin = 0;
}
$hostname = 'localhost';
$username = '*******';
$password = '******';
$conn = new PDO("mysql:host=$hostname;dbname=sv", $username, $password);
$sql = "UPDATE schedule SET currentlocation = ?, currentlocationstart = ? WHERE apptid= ? ";
$q = $conn->prepare($sql);
$q->execute(array($checkin,$currentlocationstart, $apptid));
?>
locationchange.php
<?php
date_default_timezone_set('America/Denver');
$apptid = $_REQUEST['selectId'];
$currentlocationstart = date("Y-m-d H:i:s");
if(isset($_REQUEST['locationSelect'])){
$currentLocation = $_REQUEST['locationSelect'];
}
$hostname = 'localhost';
$username = '*****';
$password = '*******';
$conn = new PDO("mysql:host=$hostname;dbname=sv", $username, $password);
$sql = "UPDATE schedule SET currentlocation = ?, currentlocationstart = ? WHERE apptid= ? ";
$q = $conn->prepare($sql);
$q->execute(array($currentlocation,$currentlocationstart, $apptid));
?>
和 checkout.php
<?php
date_default_timezone_set('America/Denver');
$apptid = $_REQUEST['buttonId'];
$currentlocationstart = date("Y-m-d H:i:s");
if(isset($_REQUEST['checkOut'])){
$checkin = 1000;
}
$hostname = 'localhost';
$username = '*********';
$password = '********';
$conn = new PDO("mysql:host=$hostname;dbname=sv", $username, $password);
$sql = "UPDATE schedule SET currentlocation = ?, currentlocationstart = ? WHERE apptid= ? ";
$q = $conn->prepare($sql);
$q->execute(array($checkin,$currentlocationstart, $apptid));
?>