简体   繁体   中英

In AJAX url how to get the parameter values to php varibles?

By using the ajax script I am creating the table.

table = table_to_use.DataTable({

  ajax: {
    url: "example.php?getvalues",
    dataSrc: ""
   },

Below mentioned code from PHP server-side.

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;
}

My question is, In url i am passing parameter values how can Get that parameter values?

URL:**example.php?id=1243&status=queued**

Thanks in advance.

you can get your id value from this url (example.php?id=1243&status=queued) as

$_GET['id'] 

and status value as

$_GET['status'].

Use a foreach on the $_GET array

foreach($_GET as $key=> $value) {

echo $key.' : '.$value;
}

By using $_GET or $_REQUEST Global variables of PHP. You can access the URL parameters.

Example :

Url : example.php?id=1243&status=queued

// Returns 1243.
$id = $_GET['id'];

// Returns queued.
$status = $_GET['status'];

In ajax :

ajax: {
        url: "example.php?getvalues",
        dataSrc: "",
        method: GET
    },

and for the Url : example.php?id=1243&status=queued

USE :

// Returns 1243.
$id = $_GET['id'];

// Returns queued.
$status = $_GET['status'];

to get the values from URL of id and status parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM