jQuery ajax检查并提交表单,当ajax返回nofound时总是必须提交两次
我用 ajax 检查该名称是否已找到或未找到。当数据返回找到时它工作正常,但是当它返回未找到时,我必须再次提交才能触发它。
有人对此有建议或更好的解决方案吗?
$('#formletter').submit(function() {
var name = $('#name').val();
if ($.formLoading != false) {
$.ajax({
type: 'POST',
url: "submit_ajax_contents.php",
data: "namecheck="+name,
success: function(data) {
if(data == 'nofound'){
$.formLoading = false;
$('#formletter').submit();
}else{
alert('found');
$.formLoading = true;
}
}
});
return false;
} else {
return true;
}
});
});
非常感谢:)
I have this ajax check to see if the name is found or nofound. It works fine when data returns found, but when it return nofound, I must submit it again to trigger it.
Does anyone have a suggestion or a better solution for this?
$('#formletter').submit(function() {
var name = $('#name').val();
if ($.formLoading != false) {
$.ajax({
type: 'POST',
url: "submit_ajax_contents.php",
data: "namecheck="+name,
success: function(data) {
if(data == 'nofound'){
$.formLoading = false;
$('#formletter').submit();
}else{
alert('found');
$.formLoading = true;
}
}
});
return false;
} else {
return true;
}
});
});
Many thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想要执行非异步 ajax 调用:(我没有测试此代码)
You might want to do a non-async ajax call: (I didn't test this code)