axios 结束后是否需要加上 return false?
axios后面是否需要加上 return false?
表单里并没有加上return之类的method,一旦验证失败基本来不及输出swal就跳转了,form默认跳转到本页,是这样吧
$('.btn-create-order').click(function () {
...
axios.post('{{ route('orders.store') }}', req)
.then(function (response) {
swal('订单提交成功', '', 'success');
}, function (error) {
if (error.response.status === 422) {
var html = '<div>';
_.each(error.response.data.errors, function (errors) {
_.each(errors, function (error) {
html += error+'<br>';
})
});
html += '</div>';
swal({content: $(html)[0], icon: 'error'});
} else {
swal('系统错误', '', 'error');
}
});
return false;
});
推荐文章: