丢失查询字符串参数由于截断周围&

时间:2013-08-18 15:44:37

标签: php javascript ajax get

我正在尝试使用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 - 

我已尝试在&amp; s上使用encodeURIComponent,但这导致$ GET没有正确分解字符串,所以你最终得到这样的东西。

degreecourse=Biomedical%20Sciences%26%23038%3Binterest%3DAny%26%23038%3Bgradyear%3D2013
Args = Degree - Biomedical Sciences&interest=Any&gradyear=2013 Interest - Year -   

0 个答案:

没有答案