第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

為什么我直接就跳進(jìn)了error:function里面,沒有進(jìn)行success:function

$.ajax({
????url:"/ErrorController/ajaxError",
????type:"POST",
????async:false,
????success:function?(data)?{
????????if?(data.status?==200?&&?data.msg?==?"OK"){
????????????alert("succcess");
????????}?else{
????????????alert("error:"?+data.msg);
????????}
????},
????error:?function?(response,ajaxOptions,thrownError)?{
????????alert("error");
????}
});


handler.java

@RestController
public?class?AjaxExceptionHandler?{

????@ExceptionHandler(value?=?Exception.class)
????public?JSONResult?defaultExceptionHandler(HttpServletRequest?request,Exception?e)?throws?Exception{
????????e.printStackTrace();
????????return?JSONResult.errorException(e.getMessage());
????}
}

ajaxError.html:

<!DOCTYPE?html>
<html?lang="en"?xmlns:th="http://www.thymeleaf.org">
<head>
????<meta?charset="UTF-8">
????<title>異常捕獲</title>
????<script?src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>

</head>
<body>
????<h1>測試ajax錯(cuò)誤異常</h1>

????<script?th:src="@{/js/ajaxerror.js}"></script>
</body>
</html>

controller里面的代碼:

@RequestMapping("/testAjaxError")
public?String?testAjaxError(){
????return?"/thymeleaf/ajaxError";
}


@RequestMapping("/ajaxError")
@ResponseBody
public?JSONResult?ajaxError(){

????int?a=1/0;

????return?JSONResult.ok();
}


正在回答

2 回答

將類注解

@ControllerAdvice

改成

@RestControllerAdvice

就好了


0 回復(fù) 有任何疑惑可以回復(fù)我~
AjaxExceptionHandler類上沒有加@controlleradvice注解,可能異常統(tǒng)一處理并未生效,導(dǎo)致進(jìn)入了error?function


0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

為什么我直接就跳進(jìn)了error:function里面,沒有進(jìn)行success:function

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號