Ajax - 将数据添加到URL

时间:2011-09-13 14:07:37

标签: javascript ajax

我第一次使用Ajax,我想在URL上附加两个数据。 这是我正在使用的代码 - 不起作用。

如何在目标网址中附加两个值?

<script type="text/javascript">
function show(first, second)
{
if (first =="" || second =="" )
  {
  document.getElementById("searchDiv").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("searchDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","search.php?type="+first&"place"=+second,true);
xmlhttp.send();
}
</script>

附加到网址的数据似乎不正确。我正在将数据附加到typeplace Here's the example我正在使用,它需要一个值,但我想让我接受两个值。 任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:4)

错字

xmlhttp.open("GET","search.php?type="+first&"place"=+second,true);

应该是

xmlhttp.open("GET","search.php?type="+first+"&place="+second,true);
相关问题