Advertisement
robjones90

Untitled

Nov 23rd, 2019
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  Promise.all([
  2.             fetch("http://127.0.0.1:8000/api/customers/"),
  3.             fetch("http://127.0.0.1:8000/api/profiles/"),
  4.         ]).then(allResponses => {
  5.             const response1 = allResponses[0].json()
  6.             const response2 = allResponses[1].json()
  7.            
  8. // var test == to the Json returned in response 2
  9.             test = {
  10.                 "count": 1,
  11.                 "next": null,
  12.                 "previous": null,
  13.                 "results": [
  14.                     {
  15.                         "city": "London, England, UK",
  16.                         "pk": 1,
  17.                         "longitude": 51.5074,
  18.                         "latitude": 0.1278
  19.                     }
  20.                 ]
  21.             }
  22.             console.log(test.results[0].pk) //This results in => 1
  23.  
  24.             console.log(response2.results[0].pk) //This results in undefined.
  25.  
  26. //Uncaught (in promise) TypeError: Cannot read property '0' of undefined
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement