问题描述
抱歉,如果有一些错误,但我是个菜鸟,我也是第一次在 StackOverflow 上发帖。
我正在尝试配置一个提交表单,该表单控制插入的 PIN 是否正确,如果正确,则继续提交。我做了一些在线研究,发现我们可以使用 jQuery 来实现 event.preventDefault()
,我试图将它插入到我的 AJAX 请求中,但它看起来并没有阻止表单被保存。
代码如下:
function verifyOTP() {
$(".error").html("").hide();
$(".success").html("").hide();
var otp = $("#contomovimentato").val();
var PIN = $("#PINvalue").val();
var input = {
"otp" : otp,"PIN" : PIN,"action" : "verify_otp"
};
if (otp != null) {
$.ajax({
url : 'm_ajaxpinr.php',type : 'GET',dataType : "json",data : input,success : function(response) {
$("." + response.type).html(response.message)
$("." + response.type).show();
},error : function() {
alert("ss");
}
});
} else {
$(".error").html('XPIN non valido.')
$(".error").show();
error : function(event) { event.preventDefault(); };
}
//if I insert "return false;" here the submit is always blocked
}
我检查了 atom 括号是否正确并且看起来是正确的。 我应该如何使用 preventDefault() 的任何想法? 我还检查了 m_ajaxpinr.php 的输出是否正确,确实如此。我也这样试过,但还是不行...
if (otp != null) {
$.ajax({
url : 'm_ajaxpinr.php',success : function(response) {
$("." + response.type).html(response.message)
$("." + response.type).show();
$("form").submit(function(event) {
if (response.type == 'success')
{
alert(response.type);
}
else if (response.type == 'error')
{
alert(response.type);
event.preventDefault();
}
});
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)