如何return false to parent event from its child in js
How to return false to parent event from its child in js
这是我的js代码:
$(function () {
$('#buyer').on('submit', function (event) {
var userCaptcha = $('#jCaptcha').val();
$.post('Jcaptcha', {
jcaptcha: userCaptcha
}, function (responseText) {
if (responseText !== "") {
$('#ajaxcall').html(responseText);
//return from here
}
});
});
});
我想 return false
我的提交事件,这样表单就不会被提交。
您可以首先阻止表单提交,而不是在 ajax 回调中,使用 event.preventDefault();
。您的实际提交必须通过 ajax 处理 - 我假设这就是您的 $.post
.
中发生的情况
$(function () {
$('#buyer').on('submit', function (event){
event.preventDefault(); // dont actually submit natively
var userCaptcha = $('#jCaptcha').val();
$.post('Jcaptcha', { jcaptcha : userCaptcha }, function (responseText) {
if (responseText !== "") {
$('#ajaxcall').html(responseText);
}
});
});
});
这是我的js代码:
$(function () {
$('#buyer').on('submit', function (event) {
var userCaptcha = $('#jCaptcha').val();
$.post('Jcaptcha', {
jcaptcha: userCaptcha
}, function (responseText) {
if (responseText !== "") {
$('#ajaxcall').html(responseText);
//return from here
}
});
});
});
我想 return false
我的提交事件,这样表单就不会被提交。
您可以首先阻止表单提交,而不是在 ajax 回调中,使用 event.preventDefault();
。您的实际提交必须通过 ajax 处理 - 我假设这就是您的 $.post
.
$(function () {
$('#buyer').on('submit', function (event){
event.preventDefault(); // dont actually submit natively
var userCaptcha = $('#jCaptcha').val();
$.post('Jcaptcha', { jcaptcha : userCaptcha }, function (responseText) {
if (responseText !== "") {
$('#ajaxcall').html(responseText);
}
});
});
});