-1

I am using Laravel at backend and Aurelia on front. I know this has been answered many times before but none solution is working out for me. I want to send custom messages back in aurelia and extract them. Thing I am trying to do:


      //post api
       .then(response => response.json())
                .then(jsonData => {                   

                   if(jsonData.msg== true)  
                   {                
                    document.getElementById('close_add_new_modal').click();
                   } else {
                    console.log(`Error!`); 
                   }

              });

Everytime here I get the exception:

Possible Unhandled Promise Rejection: TypeError: Cannot read property 'json' of undefined

Backend: How I am trying to send msg:

 return response()->json(['msg' => 'true']);

To solve the error I referred to this post: Possible Unhandled Promise Rejection. Cannot read property of undefined

Followed, but issue remained same. Could anyone tell me where am I wrong or what is correct way of fetching custom messages?

Maha Waqar
  • 439
  • 5
  • 15

1 Answers1

0

Try using this

return json_encode(['msg' => 'true']);

and also try to use aurelia-fetch-client for api requests handling

import `{HttpClient, json} from 'aurelia-fetch-client';

https://aurelia.io/docs/plugins/http-services/

  • Though I declared this answer right but I have one more question. This method works fine while dealing with update method... but when you use "post" and then wanted to receive response same errors comes as mentioned above. ````Possible Unhandled Promise Rejection: TypeError: Cannot read property 'json' of undefined```` – Maha Waqar Jan 22 '20 at 09:18