AJAX-OnSubmit问题
|
我对AJAX相当陌生,所以请原谅我。
我必须形成-第一拳有效,但第二拳无效,我也不知道为什么。第一个html表单没有提交按钮,但第二个表单有。它们都使用相同的javascript函数。
<script type=\"text/javascript\">
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\",\"server_script.php?q=\"+str,true);
xmlhttp.send();
}
</script>
从1开始
<form>
<select name=\"users\" onchange=\"showUser(this.value)\">
<option value=\"0001\">0001</option>
0002
人员信息将在此处列出。
从2:
<form onsubmit=\"showUser(this.foo.value)\">
<input type=\"foo\" >
<input type=\"submit\" >
</form>
<br />
<div id=\"txtHint\"><b>Person info will be listed here.</b></div>
没有找到相关结果
已邀请:
2 个回复
倾坞髓
事件,该事件具有将表单回发到服务器的默认行为。因此,您必须在该事件上输入
或
才能完成ajax代码。最简单的解决方法是简单地添加return false:
信藉乒