[英]My data posts to a new page rather than the specified div
Why does my post data appear on a new blank page rather than the div I specified? 为什么我的帖子数据显示在新的空白页上而不是我指定的div上? This script is in the head of a page called order.php.
该脚本位于名为order.php的页面的顶部。 I want the data submitted to be written in the "message" div I created on order.php.
我希望提交的数据写在我在order.php上创建的“ message” div中。 But when I submit, I am redirected to update.php where the data is written on a blank page.
但是当我提交时,我被重定向到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
并且通过执行xmlhttp.open('POST', 'update.php', true);
将其发布到update.php
xmlhttp.open('POST', 'update.php', true);
This might be due to normal form submission event. 这可能是由于正常的表单提交事件。
use a simple jquery
$("#form").submit(function(){
$.post("update.php",{paramertes:'child_name_'+$("#child_name").val()},function(data){
$("#message").html(data);
})
return false;//don't forget to use this
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.