我正在尝试使用 GET 从数据库中检索数据。但是,当发送多个值时,查询字符串被截断,所以我只看到第一个。即发送 somepage.com/file.php?val1=v1&val2=v2 然后使用 $SERVER['QUERY STRING'] 导致“val1=v1&”,因此第二个参数丢失。
这是代码的重要部分
Javascript:
<script type="text/javascript">
function showUser(degreecourse, interest, gradyear)
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('GET',"/getcandidates.php?degreecourse="+ encodeURIComponent(degreecourse) + "&interest=" + encodeURIComponent(interest) + "&gradyear=" + encodeURIComponent(gradyear), false);
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 || xmlhttp.status==200)
{
document.getElementById("info").innerHTML=xmlhttp.responseText;
}
else {
document.getElementById("info").innerHTML="Error";
}
}
xmlhttp.send();
return false; }
PHP
$degreecourse=$_GET['degreecourse'];
$interest=$_GET['interest'];
$gradyear=$_GET['gradyear'];
$fullstring = $_SERVER["QUERY_STRING"];
echo $fullstring."\n";
echo "Args = Degree - ".$degreecourse." Interest - ".$interest." Year - ".$gradyear."\n";
输出
degreecourse=Computer%20Science&
Args = Degree - Computer Science Interest - Year -
我已经尝试在 &s 上使用 encodeURIComponent ,但这会导致 $GETs 没有正确分解字符串,所以你最终会得到这样的结果。
degreecourse=Biomedical%20Sciences%26%23038%3Binterest%3DAny%26%23038%3Bgradyear%3D2013
Args = Degree - Biomedical Sciences&interest=Any&gradyear=2013 Interest - Year -