|
 |
|
พี่ครับผมใช้ ajax เช็คว่าห้องว่างไหม ทำไมผมกดแล้วมันไม่แสดงค่าให้ผมอ่าครับ |
|
 |
|
|
 |
 |
|
Code (PHP)
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<script>
$( function() {
$( ".bday" ).datepicker({minDate: '3',dateFormat: 'yy-mm-dd'});
$( ".btop" ).textarea();
} );
/* $(function() {
$('body').on('click','.input_date', function() {
$(this).datepicker({minDate: '3',dateFormat: 'yy-mm-dd'});
});
});*/
var HttPRequest = false;
function doCallAjax() {
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = 'data.php';
var pmeters = "myRoom=" + encodeURI( document.getElementById("roomId").value) +
"&myDate1=" + encodeURI( document.getElementById("bday").value ) +
"&mytime=" + encodeURI( document.getElementById("btime").value ) ;
//var pmeters = 'myName='+document.getElementById("txtName").value+'&my2='; // 2 Parameters
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);
HttPRequest.onreadystatechange = function()
{
if(HttPRequest.readyState == 3) // Loading Request
{
document.getElementById("mySpan").innerHTML = "Now is Loading...";
}
if(HttPRequest.readyState == 4) // Return Request
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
}
}
/*
HttPRequest.onreadystatechange = call function .... // Call other function
*/
}
</script>
<table class="table" >
<tr>
<th>ชื่อห้อง</th>
<th>ที่ตั้ง</th>
<th>หัวข้อในการจอง</th>
<th>วัน/เวลา ในการจอง</th>
<th>จอง</th>
<th>ตรวจสอบ</th>
</tr>
<? while ($rowrb = mysqli_fetch_array($resultsqlb)) { ?>
<form action="inroom.php?todo=book" method="POST" name="fm" id="fm" onSubmit="JavaScript:return fncSubmits();">
<tr>
<td><?= $rowrb[names];?></td>
<td><?= $rowrb[loca];?></td>
<td><textarea name="btop" class="btop"></textarea></td>
<td><input name="bday" class="bday" type="text" readonly="readonly">
<select name="btime" id="btime">
<option value="">เลือกเวลา</option>
<option value="1">เช้า(08.00-12.00)</option>
<option value="2">บ่าย(13.00-16.00)</option>
</select></td>
<td><input name="roomId" id="roomId" type="hidden" value="<?= $rowrb['rid'];?>">
<input type="submit" class="btn btn-primary" value="จอง" > </td>
<td width="15%">
<input type="button" class="btn btn-primary" value="ตรวจสอบ" onClick="JavaScript:doCallAjax();"> </td>
<td width="25%"><strong><span id="mySpan" style="color:#FF3333">คลิ๊กเพื่อตรวจสอบห้องประชุม</span></strong></td>
</tr>
</form>
<?}?>
</table>
หน้าเช็คครับ
Code (PHP)
include'inc/function.php';
$dblink = connect_db();
$strSQL = "SELECT * FROM book WHERE dates='".$_POST["myDate1"]."' and btime= '".$_POST["mytime"]."' and status='1' rid = '".$_POST["myRoom"]."' ";
echo "$strSQL";
$objQuery = mysqli_query($dblink, $strSQL);
$objResult = mysqli_fetch_array($objQuery);
if($objResult)
{
echo "ห้องไม่ว่าง มีคนจองแล้ว!";
}
else
{
echo "ห้องว่าง สามารถจองได้!";
}
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2016-10-02 20:14:04 |
By :
erlnw001 |
View :
820 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเรียกไฟล์ php ขึ้นมาตรง ๆ นะครับ ว่ามันได้หรือเปล่าครับ 
|
 |
 |
 |
 |
Date :
2016-10-03 17:04:44 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เรียกได้ครับพี่
|
 |
 |
 |
 |
Date :
2016-10-03 20:03:51 |
By :
erlnw001 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขั้นตอนต่อไปคือ make ค่าตัวแปร เพื่อ Test
|
 |
 |
 |
 |
Date :
2016-10-04 12:06:35 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|