似乎我的脚本无法调用 ajax_test.php 中的 PHP 函数。我正在尝试在更改下拉框时实现对 php 函数的调用。我的 html 页面是 index.php。代码如下。任何人都可以启发我吗?索引.php
<script>
$(document).ready(function(){
$("#cm").change(
function ()
{
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");
}
//code goes here
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var test = $.ajax
({
type: "POST",
url: "ajax_test.php",
dataType: "json",
}).done(function(){
document.getElementById("box").innerHTML = xmlhttp.responseText;
});
}
}
xmlhttp.open("POST","ajax_test.php",true);
xmlhttp.send();
});
});
</script>
<div>
<div id="box"><p>a</p></div>
<form>
<select id="cm">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
</form>
ajax_test.php
<?php
function hey(){
echo '<p>hey</p>';
}
?>