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