我有一个提交按钮。单击它时,我正在尝试从 php 回调文件返回响应。但我没有得到任何回应。点击提交后,我得到以下网址
http://localhost/folder/new.php?submit=Submit+Query
PHP 文件命名为new.php
<script language="javascript" type="text/javascript">
function callme()
{
var req;
try
{
req = new XMLHttpRequest();
}catch (e)
{
try
{
req = new ActiveXObject("Msxml2.XMLHTTP");
}catch (e)
{
try
{
req = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e)
{
alert("Your browser broke!");
return false;
}
}
}
req.onreadystatechange=function(){
if(req.readyState==4)
{
document.getElementById("display_area").innerHTML=req.responseText;;
}
}
req.open("GET","phpcall.php",true);
req.send();
}
</script>
和 PHP 回调文件 - 命名为 phpcall.php
<?php
echo "returning from phpcall.php";
?>
这里可能有什么错误?网址更改为的原因是什么
http://localhost/folder/new.php?submit=Submit+Query
在表格中添加部分-
<form name='myForm'>
Max Age: <input type='text' id='age' /> <br />
Max WPM: <input type='text' id='wpm' />
<br />
Sex: <select id='sex'>
<option value="m">m</option>
<option value="f">f</option>
</select>
<input type='button' onclick='ajaxFunction()'
value='Query MySQL'/>
</form>
<div id='ajaxDiv'>Your result will display here</div>