【发布时间】:2015-03-27 06:32:04
【问题描述】:
我正在为我的项目开发 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>
【问题讨论】:
-
从 HTML 中获取参数时会发生什么?
-
但是当我使用 xmlhttp.open("GET","portal.php?searccategory=Birdid&searchValue=2",true);它工作
标签: html ajax parameters get