开发者

How to pass querystring with JQuery?

A very good morning, i am currently working on a simple php project, the goal of the application is to read Oracle data and display the result, i've completed this part. I am having a little doubt on how to pass querystring along with JQuery开发者_运维问答, please advice. Many thanks in advance.

index.php - this is where i am passing the querystring index.php?campus=abc&floor=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.."/>&nbsp;&nbsp;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>&nbsp;&nbsp;|&nbsp;&nbsp;<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>";
?>

Hope someone here can shed some light to point me in the correct direction, many thanks in advance.


Since you're not posting any data other than your query string I think you want to be using GET instead of POST, but since your php file uses $_REQUEST both will work. Just format your data like this:

type: 'GET',
data: {campus: 'abc', floor: 'xyz'},
url: 'timetable.php',
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜