一个非常愉快的早晨,我目前正在开发一个简单的php项目,该应用程序的目标是读取Oracle数据并显示结果,我已经完成了这一部分。我对如何将查询字符串与JQuery一起传递有点疑问,请指教。非常感谢提前。
index.php - 这是我传递查询字符串的地方 ?的index.php校园= ABC&安培;楼层= XYZ
<html>
<head>`enter code here`
<title>Olympia College :: Kiosk</title>
<link rel="Stylesheet" type="text/css" href="assets/css/kiosk.css" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
// $(document).ready(function()
// {
// $("#responsecontainer").load("contents.php");
// var refreshId = setInterval(function()
// {
// $("#responsecontainer").load('contents.php?randval='+ Math.random());
// }, 1000);
// $.ajaxSetup({ cache: false });
// });
function update() {
$("#notice_div").html('<img src="indicator.gif" alt="Synchronizing data, please wait a moment.."/> Synchronizing data, please wait a moment..');
$.ajax({
type: 'POST',
// data: '{campus, floor}',
url: 'timetable.php',
timeout: 5000,
success: function(data) {
$("#some_div").html(data);
$("#notice_div").html('');
window.setTimeout(update, 10000);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
$("#notice_div").html('Timeout contacting server..');
window.setTimeout(update, 60000);
}
});
}
$(document).ready(function() {
update();
});
</script>
</head>
<body>
<!--<div id="responsecontainer">
<?php //echo date("l, F d, Y h:i:s" ,time());?>
</div>-->
<div id="main">
<div id="left"><img src="assets/images/oc_logo.png" alt="Olympia College Malaysia"></img></div>
<div id="right"><div id="notice_div"></div><div id="fright"><a href="setting.php" title="Change settings">Setting</a> | <a href="bug.php" title="Send bug report">Bug Report</a></div></div>
</div>
<div id="line"></div>
<br />
<div id="some_div"></div>
</body>
timetable.php
<?php
$datasource = "******";
$hostname = "******";
$username = "*****";
$password = "*****";
$database = "*****";
$campus = $_REQUEST['campus'];
$floor = $_REQUEST['floor'];
//KL CAMPUS
if ($campus == 'ockl')
$campus = 'KL CAMPUS';
elseif ($campus == 'ocpj')
$campus = 'PJ CAMPUS';
elseif ($campus == 'ocpg')
$campus = 'PENANG CAMPUS';
elseif ($campus == 'ocip')
$campus = 'IPOH CAMPUS';
elseif ($campus == 'ockt')
$campus = 'KUANTAN CAMPUS';
elseif ($campus == 'ocjb')
$campus = 'JB CAMPUS';
//echo $_REQUEST['campus'];
$connect = odbc_connect($datasource, $username, $password);
if(!$connect){
echo "Unable to connect!<br /><br />";
}
else {
//echo "Successfully connected!<br /><br />";
};
$query = "SELECT DISTINCT
RESOURCE_DAY_TIME_SETUP.DAY,
RESOURCE_DAY_TIME_SETUP.FLOOR_CODE,
RESOURCE_DAY_TIME_SETUP.RESOURCES_CODE,
RESOURCE_DAY_TIME_SETUP.CAMPUS
FROM RESOURCE_DAY_TIME_SETUP WHERE CAMPUS LIKE '" . $campus . "'";
$result = odbc_exec($connect, $query);
echo "<table border='1'>";
echo "<tr> <th>Day</th> <th>Floor</th> <th>Room</th> <th>Duration</th> <th>Start</th> <th>End</th> <th>Lecturer</th> <th>Status</th> <th>Campus</th> </tr>";
while (odbc_fetch_row($result)){
$day = odbc_result($result,1);
$floor_code = odbc_result($result, 2);
$resources_code = odbc_result($result,3);
$campus = odbc_result($result,4);
echo "<tr>";
echo "<td>$day</td>";
echo "<td>$floor_code</td>";
echo "<td>$resources_code</td>";
echo "<td>$resources_code</td>";
echo "<td>$resources_code</td>";
echo "<td>$resources_code</td>";
echo "<td>$resources_code</td>";
echo "<td>$resources_code</td>";
echo "<td>$campus</td>";
echo "</tr>";
}
odbc_close($connect);
echo "</table>";
?>
希望这里有人能够指出我正确的方向,非常感谢提前。
答案 0 :(得分:1)
由于您没有发布除查询字符串以外的任何数据,我认为您希望使用GET而不是POST,但由于您的php文件使用$_REQUEST
,因此两者都可以。只需格式化您的数据:
type: 'GET',
data: {campus: 'abc', floor: 'xyz'},
url: 'timetable.php',