我有一个下拉选择列表和一个按钮,我在其中插入了一个onclick事件,这样每当有人点击该按钮时,它将调用一个基本上包含ajax的函数,当执行它时将包含一个php文件.在我的php文件中,它从所选的下拉列表中获取值,然后它将显示一个警告选项,但它不显示任何警报.
以下是我的代码: –
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").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("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","user.php?q="+str,true);
xmlhttp.send();
}
Select a person:
Peter Griffin
Lois Griffin
Glenn Quagmire
Joseph Swanson
user.php的
$q=$_GET["q"];
if($q ==1)
{
echo '
alert("Hello")
';
}
else {
echo "No";
}
?>
任何帮助将不胜感激,并感谢您的帮助提前:)