Javascript help: Issue with promise scope

Javascript help: Issue with promise scope
0

#1

Hi there. Here is a jsFiddle of the Camper Leaderboard project I just started: https://jsfiddle.net/valerieseer/eo5kkxLt/

Right now I’m testing 2 Ajax calls, which are in the getCampers function. I am trying to console.log the results from the 2 Ajax calls, but I’m having an issue reaching the scope of the results from the promise (line 10). Any help would be appreciated. Thanks!


#2

Hey @valeseer,
from looking at your code, everything is mashed together, making it hard to understand what belongs where.
You have nested somewhere around 4 functions inside one another.
Also, the thing with Promises, is that you are creating another scope and the “this” variable will not refer to what you want it to.
I would try to start out with just making one ajax call and handling that response. From there, I would complicate things and add the needed logic that you are requesting.