Я возвращаю пользовательский ответ от моего php, и я не знаю, как я могу использовать этот ответ для моей страницы. Я пытаюсь использовать console.log, чтобы увидеть статус и сообщения, но не повезло.
if ($message->send()){
return response()->json([
'status' => 'success',
'msg' => 'Message send =)'
],201);
}else{
return response()->json([
'status' => 'error',
'msg' => 'Message did not send =('
],422);
}
и в моем сценарии
axios.post('url',params)
.then(function(){
console.log('send');
})
.catch(function(error){
if (error.response){
console.log(error.response.data.msg);
}else if(error.request){
console.log(error.response.data.msg)
}else{
console.log(error.response.data.msg);
}
});
Я хочу получить статус и сообщение
но console.log (error.response.data.msg) имеет значение undefined .
Я делаю неправильный возврат или неверный console.log ()?
благодарю за помощь.
Я исправил это!
я заменяю функцию (ошибка) на функцию (ответ).
просто так
.then(function(response){
console.log('response.data.msg');
console.log('response.data.status');
})
.catch(function(response){
console.log('response.data.msg');
console.log('response.data.status');
});