繁体   English   中英

我的数据发布到新页面而不是指定的div

[英]My data posts to a new page rather than the specified div

为什么我的帖子数据显示在新的空白页上而不是我指定的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并且通过执行xmlhttp.open('POST', 'update.php', true);将其发布到update.php xmlhttp.open('POST', 'update.php', true);

这可能是由于正常的表单提交事件。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM