为什么我的帖子数据出现在新的空白页而不是我指定的 div 上?该脚本位于名为 order.php 的页面的头部。我希望提交的数据写入我在 order.php 上创建的“message”div 中。但是当我提交时,我被重定向到 update.php,其中数据写在空白页上。
<script type="text/javascript">
function insert() {
if (window.XMLHttpRequest) {
xmlhttp = new XLMHttpRequest();
} else {
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("message").innerHTML = xmlhttp.responseText;
}
}
parameters = 'child_name'+document.getElementById('child_name').value;
xmlhttp.open('POST', 'update.php', true);
xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xmlhttp.send(parameters);
}
</script>
最佳答案
您当前的页面是 order.php
并通过执行以下操作将其发布到 update.php
xmlhttp.open('POST', 'update.php ', true);
关于javascript - 我的数据发布到新页面而不是指定的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12936657/