我有这样的情况。有如下所示的选择表单,并且想要调用 ajax 函数来获取结果取决于更改选择表单,但是从 ajax 获取整个页面
这是脚本
<html>
<head>
<title>HI</title>
<link rel="stylesheet" href="./scripts/css/default.css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<form method="post">
<select name="s" id="s">
<option value="one">A</option>
<option value="two">B</option>
<option value="three">C</option>
</select>
</form>
Hello guys ...
<div id="xe"></div>
<script type="text/javascript">
document.getElementById("s").onchange = function(){
var h = false;
if (window.XMLHttpRequest){
h = new XMLHttpRequest();
}
if (h){
h.open("POST","index.php",true);
h.onreadystatechange = function(){
if (h.readyState==4 && h.status==200){
document.getElementById("xe").innerHTML = h.responseText;
}
};
h.send("s=" + document.getElementById("s").value);
}
};
</script>
<?php
if (isset($_POST['s'])){
echo $_POST['s'];
}
?>
</body>
</html>
有任何想法吗 ?请帮忙,谢谢...