无法从ajax库访问laravel响应
问题描述:
//编辑:嗯......这是firefox中的一个萤火虫错误。在铬它的作品...无法从ajax库访问laravel响应
我使用Laravel 5.3与Vue 2.0和axios ajax库。
下面是测试控制器,其中i从laravel返回response
:
public function testMethod() {
return response('this is an error', 500);
}
这里是我的Ajax调用:
http(`fetch-data`).then(response => {
const data = response.data;
console.log(data);
}).catch(error => {
console.log(error); // <- This doens't work, he show my nothing
alert(error);
});
的问题是,我需要它返回的错误消息从laravel到我的客户catch
。但是如果我是他们,他什么都不给我看。如果我alert
错误,他给我以下消息:Error: Request failed with status code 500
。
为什么我不能访问像error.statusCode
,error.statusMessage
?
答
尝试
return response()->json('this is an error', 500);