![](/img/trans.png)
[英]How to set global javascript varibles by php so the values are not public?
[英]In AJAX url how to get the parameter values to php varibles?
通過使用ajax腳本,我創建了表。
table = table_to_use.DataTable({
ajax: {
url: "example.php?getvalues",
dataSrc: ""
},
下面提到的來自PHP服務器端的代碼。
if (isset($_GET["getvalues"])) {
$sql = setupSql();
$query = "SELECT * FROM testing WHERE expiration > NOW()";
$result = mysql_query($query);
echo "[";
echo json_encode(mysql_fetch_assoc($result));
while ($row = mysql_fetch_assoc($result))
echo "," . json_encode($row);
echo "]";
//$queue_data = listQueue();
//echo $queue_data;
return;
}
我的問題是,在url中,我正在傳遞參數值,如何獲取該參數值?
URL:**example.php?id=1243&status=queued**
提前致謝。
您可以通過以下網址獲取您的ID值(example.php?id = 1243&status = queued)為
$_GET['id']
和狀態值為
$_GET['status'].
在$ _GET數組上使用foreach
foreach($_GET as $key=> $value) {
echo $key.' : '.$value;
}
通過使用$_GET
或$_REQUEST
PHP的全局變量。 您可以訪問URL參數。
范例:
網址: example.php?id=1243&status=queued
// Returns 1243.
$id = $_GET['id'];
// Returns queued.
$status = $_GET['status'];
在ajax中:
ajax: {
url: "example.php?getvalues",
dataSrc: "",
method: GET
},
並為網址:example.php?id = 1243&status = queued
采用 :
// Returns 1243.
$id = $_GET['id'];
// Returns queued.
$status = $_GET['status'];
從id and status
參數的URL獲取值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.