JSON API project JSON API project
0.0 0


Hello, I just did the JSON API project, here is my code:
I have a few questions concerning the project.
In JS on line 62, if istead of var displayName= data3.responseJSON.message; I wanted to do displayName= deletedFollowers[i] + "custom message"; But the deletedFollowers[i] returned undefined. Why so ?
Also, on line 55 I used channels instead of users in the url: "**channels**/"+deletedFollowers[i] , because users returned error 422 with one of the channels that doesen’t exist. Which of the two (channels/users) would be more correct to use when doing the call for the non existing channels/users in the url ? And what does the error 422 mean ?


With regards to line 62, I think you are misunderstanding how AJAX works. The a stands for asynchronous, meaning that JS doesn’t wait for AJAX to finish before moving on. By the time the AJAX routines come back, the for loop has finished and i is now 2 (the exit condition for the for loop. If you want i to still mean what you want, you’ll have to bind it somehow.

You can confirm this behavior by adding the line:

console.log("*** i = " + i + " - " + deletedFollowers[i]);

at line 63.

There are also some other errors in the console you should address.