|
|
|
อยากส่งค่า GET ไป2ค่า แล้วไปแสดงข้อมูลแบบ Realtime |
|
|
|
|
|
|
|
อยาก ส่ง ค่า GET ไปสองค่าแล้ว แสดงข้อมูลแบบ Realtime
https://www.thaicreate.com/tutorial/ajax-realtime.html
อันนี้โค้ดครับ
Code (PHP)
<?php
include ('config/config.php');
date_default_timezone_set("Asia/Bangkok");
?>
<!DOCTYPE html>
<html>
<head>
<title>จัดการวัตถุดิบ</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="css/styles.css" rel="stylesheet">
<link href="css/stats.css" rel="stylesheet">
<link rel="stylesheet" href="vendors/morris/morris.css">
<script language="JavaScript">
var HttPRequest = false;
function doCallAjax(Sort) {
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 = 'stats_list.php?sc_id='+document.getElementById("txt_scid").value+'&num='+document.getElementById("txt_num").value; // 2 Parameters
HttPRequest.open('GET',url,true);
HttPRequest.send(null);
var url = 'stats_list.php';
var pmeters = 'mySort='+Sort;
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;
}
}
}
</script>
</head>
<body Onload="bodyOnload();">
<script language="JavaScript">
function bodyOnload()
{
doCallAjax('b_id')
setTimeout("doLoop();",1000);
}
function doLoop()
{
bodyOnload();
}
</script>
<?php
$strSQL = "SELECT * FROM plan_order WHERE sc_id = '".$_GET["sc_id"]."' ";
$objQuery = mysqli_query($conn,$strSQL) or die ("Error Query [".$strSQL."]");
$objResult = mysqli_fetch_array($objQuery);
?>
<div class="header">
<div class="container">
<div class="row">
<div class="col-md-5">
<div class="logo">
<h1><a href="index.php">จัดการวัตถุดิบ</a></h1>
</div>
</div>
<div class="col-md-5">
<div class="row">
<div class="col-lg-12">
<div class="input-group form">
<input type="text" class="form-control" placeholder="Search...">
<span class="input-group-btn">
<button class="btn btn-primary" type="button">Search</button>
</span>
</div>
</div>
</div>
</div>
<div class="col-md-2">
<div class="navbar navbar-inverse" role="banner">
<nav class="collapse navbar-collapse bs-navbar-collapse navbar-right" role="navigation">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">My Account <b class="caret"></b></a>
<ul class="dropdown-menu animated fadeInUp">
<li><a href="profile.html">Profile</a></li>
<li><a href="login.html">Logout</a></li>
</ul>
</li>
</ul>
</nav>
</div>
</div>
</div>
</div>
</div>
<div class="page-content">
<div class="row">
<div class="col-md-2">
<div class="sidebar content-box" style="display: block;">
<?php include ('menu.php'); ?>
</div>
</div>
<div class="col-md-10">
<div class="content-box-large">
<ol class="breadcrumb">
<li><a href="index.php">หน้าหลัก</a></li>
<li><a href="calendar.php">แผนการผลิต</a></li>
<li class="active">รายละเอียดแผน</li>
</ol>
<div class="panel-body">
<br>
<?php
$strSQL2 = "SELECT * FROM plan_detail WHERE sc_id = '".$_GET["sc_id"]."' GROUP BY date ";
$objQuery2 = mysqli_query($conn,$strSQL2) or die ("Error Query [".$strSQL2."]");
?>
<div class="row">
<?php
while($objResult2 = mysqli_fetch_array($objQuery2))
{
?>
<div class="col-lg-2 col-md-4">
<div class="thumbnail" style="background-color: #ffffcc;">
<div class="caption">
<h4>วันที่ : <?php echo date('d-m-Y', strtotime($objResult2["date"])); ?></h4>
<input type="text" name="txt_scid" id="txt_scid" value="<?php echo $objResult2["sc_id"]; ?>">
<input type="text" name="txt_num" id="txt_num" value="<?php echo $objResult2["num"]; ?>">
<input name="btnButton" id="btnButton" type="button" value="Click" onClick="JavaScript:doCallAjax();">
</div>
</div>
</div>
<?php
}
?>
</div>
<span id="mySpan"></span>
</div>
</div>
</div>
</div>
</div>
<script src="js/jquery-3.1.0.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="vendors/jquery.knob.js"></script>
<script src="vendors/raphael-min.js"></script>
<script src="vendors/morris/morris.min.js"></script>
<script src="vendors/flot/jquery.flot.js"></script>
<script src="vendors/flot/jquery.flot.categories.js"></script>
<script src="vendors/flot/jquery.flot.pie.js"></script>
<script src="vendors/flot/jquery.flot.time.js"></script>
<script src="vendors/flot/jquery.flot.stack.js"></script>
<script src="vendors/flot/jquery.flot.resize.js"></script>
<script src="js/custom.js"></script>
<script src="js/stats.js"></script>
</body>
</html>
Tag : PHP, Ajax
|
ประวัติการแก้ไข 2017-04-20 11:37:58 2017-04-20 11:39:17 2017-04-20 11:40:14 2017-04-20 11:40:37
|
|
|
|
|
Date :
2017-04-20 11:35:54 |
By :
golfza034 |
View :
2114 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|