【发布时间】:2015-12-29 23:59:25
【问题描述】:
当我尝试使用 AJAX POST 时,以下 html 不起作用。
<script>
function call_hmm_scan() {
var specie = document.getElementById("specie_name").value;
var loci = document.getElementById("locus_id").value;
var params="specie_name=" + specie + "&locus_id=" + loci
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("domains").innerHTML = xmlhttp.responseText;
}
};
// xmlhttp.open("GET", "http://shenlab.sols.unlv.edu/kwatanabe/ajax_test.php?" + params, true);
// xmlhttp.send();
xmlhttp.open("POST", "http://shenlab.sols.unlv.edu/kwatanabe/ajax_test.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(params);
}
</script>
我在“ajax_test.php”中的PHP代码如下:
<?php
$specie = $_POST["specie_name"];
$loci = $_POST["locus_id"];
echo("$specie<br>");
echo("$loci");
?>
当我在我的 HTML 中取消注释 GET 行,并在我的 PHP 中将 $_POST 更改为 $_REQUEST 时,它可以工作!!
xmlhttp.open("GET", "http://shenlab.sols.unlv.edu/kwatanabe/ajax_test.php?" + params, true);
xmlhttp.send();
为什么 POST 不起作用?
【问题讨论】:
-
你为什么不用
jQuery.post()来代替呢?你被项目限制了..?