简体   繁体   English

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

[英]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.

相关问题 在反应中滚动页面而不是 div 元素 - Scroll page rather than div elements in react jQuery .load结果进入&#39;调用&#39;div(而不是指定的id)? - jQuery .load result into the 'calling' div (rather than a specified id)? 如何在同一页面而不是新页面上获得响应 - how to get the response on same page rather than on new page 路由器在同一页面上呈现组件,而不是在新页面中呈现 - Router rendering the component on the same page rather than rendering in a new page 如何在旧数据之前而不是之后插入新数据 - How to insert new data before old data rather than after Arrays 将数据打印到一个 div 中,而不是循环每个 div, - Arrays printing data into one div rather than looping each one, 如何使页面显示函数完成时而不是每个函数完成时处理的数据 - How do I get my page to display data that my functions process as they finish rather than when every function finishes 我的叠加层将页面的 rest 向下推,而不是出现在顶部 - My overlay pushes the rest of the page down rather than appearing on top 邮件脚本返回带有登录页面的电子表格,而不是电子表格数据 - Mail scripts returns spreadsheet with login page rather than spreadsheet data 返回ProgressEvent对象而不是我的模板数据的ajax代码 - ajax code returning ProgressEvent object rather than my template data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM