本质是form表单中的submit在form中,经过ajax提交,导致跳转出去后又跳回来了,解决方式如下:
1.在ajax后面加一行return false;
```$.ajax({
type: "post",
url: "{:url('Manual/add',['time'=>rand(0,999999)])}",
data: $('#form-manual-add').serialize(),//表单数据
dataType: "JSON",
cache: false,
async: false,
success: function (data) {
if (data.status == 1) {
layer.msg('操作成功!', {
time: 1000,
icon: 1
})
location.href = "{:url('Manual/index',['community'=>$selectCommunity,'position'=>$selectPosition,'house'=>$selectHouse,'selectName'=>$selectName])}";
} else {
layer.msg('操作失败!', {
time: 1000,
icon: 2
})
}
;
},
error: function (data) {
alert("异常!");
}
});
return false;
```
2.据说换成button或者移到form外侧也行,不建议,因为无法使用JQ默认校验器