cuốn sách gpt4 ai đã làm

javascript - Angularjs HTTP 方法中的异常处理

In lại Tác giả: Walker 123 更新时间:2023-11-29 04:29:23 26 4
mua khóa gpt4 Nike

我是 angularjs 的新手。我正在使用 angularjs 1.4 版本。我正在尝试处理从 Spring Controller 方法抛出的异常。但是我无法在下面的 js 中捕获异常。

可能这是重复的问题,但我已经在 SO 中搜索了解决方案。但是没有用。请给我建议。提前致谢。

在 Spring MVC Controller 方法中也抛出异常是否正确?或者如何向前端说 500 错误?

在 Angular Controller 中:

Service.calculate (obj).then(function(response){
// logic
});

在 Angular 服务中:

this.calculate = function(obj){
thử {
return $http.post(PATH+'txn/calc',obj).then(function(resp){
return resp;
});
} catch (e) {
alert(e);
}
};

Spring Controller 方法:

@RequestMapping(value = "/txn/calc", method = RequestMethod.POST)
public @ResponseBody someBean calculate(@RequestBody SomeBean someBean , HttpServletRequest request) {
thử {
// exception occurs here
} catch (Exception e) {
throw e;
}
}

câu trả lời hay nhất

Hãy thử điều này:

$http.post(url).then(function(response) {
console.log('post',response)
},
function(data) {
// Handle error here
})

关于javascript - Angularjs HTTP 方法中的异常处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44453154/

26 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress