使用 ajax get 请求发送多个 URL 参数

Send multiple URL parameters using ajax get request

我正在为我的项目开发 ajax 页面。在此页面中,我想发送一个带有多个 url 参数的 ajax 请求。我想从 html 文本框中获取此 url 参数。当我直接使用代码传递参数时,它工作正常。但是当我从 HTML 文本框调用参数时,它不起作用。

这是我的代码

<!DOCTYPE html>
<html>
<head>

<script>
function loadXMLDoc()
{
var xmlhttp;
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("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
 // xmlhttp.open("GET","portal.php?searccategory=Birdid&searchValue=2",true);
xmlhttp.open("GET","portal.php?searccategory="+searccategory+"&searchValue="+searchValue,true);

xmlhttp.send();
}
</script>
</head>
<body>


        <select name="searccategory1" >
                                    <option value="Species">Species</option>
                                    <option value="Birdid">ID</option>
                                    <option value="Age">Age</option>
                                    <option value="Sex">Sex</option>
                                    <option value="Location">Location</option>
                                    <option value="all">all</option>
                                </select>
         <input type="text" id="searccategory" required>
         <input type="text" id="searchValue" required>


<button type="button" onclick="loadXMLDoc()">Change Content</button>
<div id="myDiv"><h2>Let AJAX change this text</h2></div>


</body>
</html>

请查看它是否对您有帮助,搜索类别和搜索值 return DOM 元素。如果你想得到值请使用searccategory.valuesearchValue.value。或 document.getElementById("searccategory").valuedocument.getElementById("searchValue").value

xmlhttp.open("GET","portal.php?searccategory="+searccategory.value+"&searchValue="+searchValue.value,true);

xmlhttp.open("GET","portal.php?searccategory="+document.getElementById("searccategory").value+"&searchValue="+document.getElementById("searchValue").value,true);