我正在使用(Localhost)XAMPP Server 3.2.1
这是php文件MyAjax.php:
<?php
$data = isset($_REQUEST['data']);
if($data == "logout")
{
echo "<br />inside logout";
}
else if($data == "getReminder")
{
echo "<br />inside getReminder";
}
?>
以下url的输出应为inside getReminder
http://127.0.0.1/dashboard/TimeTable/PHP_Code/MyAjax.php?data=getReminder
并且以下url的输出应该是inside logout
http://127.0.0.1/dashboard/TimeTable/PHP_Code/MyAjax.php?data=logout
但是两个URL都返回相同的输出inside logout
。
请帮帮我这是怎么回事?
您应该按照如下方式读取URL字符串参数:
$data = $_REQUEST['data'];
所以你的代码应该是:
<?php
if (isset($_REQUEST['data'])) {
$data = $_REQUEST['data'];
if ($data == "logout") {
echo "<br />inside logout";
} else if ($data == "getReminder") {
echo "<br />inside getReminder";
}
}
?>