Javascript 表单提交而不转到目标页面
我对提交表格有疑问。我在processFabrication.php上有一个简单的表单,用于提交所有变量,然后在另一个名为processexeededqty.php的页面中将其处理到数据库 Co,在processFabrication.php中,我有Javascript 表单提交而不转到目标页面,javascript,php,oracle,Javascript,Php,Oracle,我对提交表格有疑问。我在processFabrication.php上有一个简单的表单,用于提交所有变量,然后在另一个名为processexeededqty.php的页面中将其处理到数据库 Co,在processFabrication.php中,我有 echo”“; 当我单击submit时,它进入processexeededqty.php 我的目标是 当用户单击提交时,显示确认是/否并弹出窗口 用户在确认窗口中单击“是”后,留在processFabrication.php中,但processE
echo”“;
当我单击submit
时,它进入processexeededqty.php
我的目标是
<form action='processExceededQty.php' method='post' onsubmit='reutrn show_pop_up()'>
在脚本上,您可以编写以下内容
<script>
function show_pop_up()
{
// show pop up
if(op_up_return =="Yes")
return true;
else
return false;
}
</script>
函数show_pop_up()
{
//显示弹出窗口
如果(op_up_return==“是”)
返回true;
其他的
返回false;
}
希望这会有所帮助。在您的
javascript中类似这样的内容:
function doSubmit(){
if (confirm('Are you sure you want to submit?')) {
// yes
return true;
} else {
// Do nothing!
return false
}
}
将onsubmit
添加到html
中的表单中:
<form action='processExceededQty.php' method='post' onsubmit='doSumit()'>
添加到@N0M3应答中。
在您的
了解ajax。还可以看到您可以使用jQuery吗?jQuery使.preventDefault()和$.post Ajax变得简单这与Ajax无关它的工作原理类似于charm,但如何保持重定向到流程页面?@Chriskonz..您可以将表单提交到表单页面本身,而无需将值传递到其他页面。否则,您可以将值传递到另一个页面,然后将其重定向回表单页面。如果您希望使用sumbit值而不离开需要xmlhttp请求的页面,此示例将允许提交通过return true传递,并通过return false停止。您必须使用AJAX提交数据,而不必在操作页面上返回。将解释如何在不离开页面的情况下提交您不需要添加return false或页面将提交吗?@N0M3 thx指出这一点,更新了我的答案。此处返回false
无效
<form action='processExceededQty.php' method='post' onsubmit='doSumit()'>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
function doSubmit(){
if (confirm('Are you sure you want to submit?')) {
// yes
$(this).submit(function(e){
e.preventDefault();
});
jQuery.ajax({
url : 'processExceededQty.php',
data : {'username':username}, // where first 'username' is your field name, and second one is your field's value
method: 'post',
success: function(data) {
// data is variable which has return data from `processExceededQty.php`
// do whatever you want with data
}
});
} else {
// Do nothing!
return false;
}
}