简体   繁体   中英

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? This script is in the head of a page called order.php. I want the data submitted to be written in the "message" div I created on order.php. But when I submit, I am redirected to update.php where the data is written on a blank page.

<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
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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