这是我的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
}
});
});
});我希望将false返回给我的提交事件,这样表单就不会被提交。
发布于 2015-09-07 07:58:44
首先,可以使用event.preventDefault();防止表单提交,而不是在ajax回调中提交。您的实际提交必须通过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);
}
});
});
});https://stackoverflow.com/questions/32433575
复制相似问题