Jquery ajax 表单提交后 return false?
Jquery ajax form submission even after return false?
我正在发送从同一页面上的表单收集的数据,以便通过 ajax 将查询插入 php 页面,该页面 return success/fail。但不是 ajax 调用,即使在 return false 之后我的表单也会被提交。我的表单字段名称值与 ajax post 提交的数据相同 names.there 没有错误在 php 页面上,当我尝试实际提交表单时,它起作用了。为什么即使在 return false 之后我的表单也被提交了。控制台有一些错误,但刷新页面时它会丢失。
这是我的表单域
<form method="POST" action="manuAthuntication.php" id="myform" onsubmit="return editAdmin()">
j查询码
<script>
function editAdmin(){
console.log("Here");
var aname=$("#aname").val();
var aemail=$("#aemail").val();
var depname=$("#depname").val();
var acontact=$("#acontact").val();
var adesi=$("#adesi").val();
var apass=$("#apass").val();
/* var myInput = document.getElementById('did');*/
/*myInput.disabled = false;*/
var hdid=$("#hdid").val();
var haid=$("#haid").val();
// $('#aidd').val(uid);
// var uid = sessionStorage.getItem("adminidedit");
$.ajax
({
type:'post',
url:'manuAthuntication.php',
data:{
editAdmin:"editAdmin",
aname:aname,
haid:haid,
aemail:aemail,
depname:depname,
acontact:acontact,
adesi:adesi,
apass:apass,
hdid:hdid
},
success:function(response) {
if(response=="success")
{
// console.log(" succes here");
$("#error").text(" added succesfully");
}
else
{
// console.log("here");
$("#succmssg").text("ID already exist. choose new one");
}
}
});
return false;
}
</script>
在 chrome 中,您可以打开开发人员工具并在网络下检查 preserve log
选项。
我正在发送从同一页面上的表单收集的数据,以便通过 ajax 将查询插入 php 页面,该页面 return success/fail。但不是 ajax 调用,即使在 return false 之后我的表单也会被提交。我的表单字段名称值与 ajax post 提交的数据相同 names.there 没有错误在 php 页面上,当我尝试实际提交表单时,它起作用了。为什么即使在 return false 之后我的表单也被提交了。控制台有一些错误,但刷新页面时它会丢失。
这是我的表单域
<form method="POST" action="manuAthuntication.php" id="myform" onsubmit="return editAdmin()">
j查询码
<script>
function editAdmin(){
console.log("Here");
var aname=$("#aname").val();
var aemail=$("#aemail").val();
var depname=$("#depname").val();
var acontact=$("#acontact").val();
var adesi=$("#adesi").val();
var apass=$("#apass").val();
/* var myInput = document.getElementById('did');*/
/*myInput.disabled = false;*/
var hdid=$("#hdid").val();
var haid=$("#haid").val();
// $('#aidd').val(uid);
// var uid = sessionStorage.getItem("adminidedit");
$.ajax
({
type:'post',
url:'manuAthuntication.php',
data:{
editAdmin:"editAdmin",
aname:aname,
haid:haid,
aemail:aemail,
depname:depname,
acontact:acontact,
adesi:adesi,
apass:apass,
hdid:hdid
},
success:function(response) {
if(response=="success")
{
// console.log(" succes here");
$("#error").text(" added succesfully");
}
else
{
// console.log("here");
$("#succmssg").text("ID already exist. choose new one");
}
}
});
return false;
}
</script>
在 chrome 中,您可以打开开发人员工具并在网络下检查 preserve log
选项。