Help with APIs/AJAX/JSON

I seriously need some help, or advice, or pointed in the right direction, or something. I truly love coding but I’m feeling really disheartened lately, and I feel like I’m not understanding things the way I should be or as everyone else is. The little part about JSON/AJAX taught me nothing, and left me more confused than before. I don’t understand how to do it, and I don’t have any idea where to start with the weather app challenge. Please help. :frowning:

http://json.org/example.html

When i dont understand smth i

  1. explore random sources on topic: articles , videos anything , and eventually find version which is understandable for me at least partially, or maybe everything becomes understandable more or less
  2. read the assignment carefully(again yep :)) , break it down to smaller tasks, think of what i’ve learned so far and how i can apply it/ what i can use to accomplish them,
  3. try to write tiny parts of code , testing if they work
    if nothing helps
  4. forget abt it all for some time and just relax)

reading documentation is a good idea , but it is not the simplest way imo, it usually describes stuff for those who understand the concept

You can always start with design:)) just play with markup and styles or anything you understand well or…
make up your own recipe )

1 Like

Don’t feel disheartened! I’m at the same stage as you, working on the weather app.

The thing that’s helped me is breaking the task into tiny parts and solving them one bit at a time. I used Google a lot to find out solutions for individual problems I was having because, like you, I am still no expert in JSON! I used the user cases to tell me what I needed to do and created a step-by-step list to follow. So the first thing I did was get the user’s geolocation, which we covered in one of the previous tasks.

First problem: I couldn’t connect to the API. Used the same method as the random quote generator. This time I found that I needed CORS to connect. Once I’d connected I went to the next problem, how to acquire the data I needed… and so on.

If you don’t know where to start just look at the user case in the project description.

  1. Get geolocation.
  2. Connect to weather API
  3. Get the data you need out of the API (e.g. temperature)
  4. Display the data.

I’m up to the stage where I need to create a function that will switch the temperature between Fahrenheit and Celsius.

I was more flustered with the last JSON task (the random quote generator) because I was trying to solve it quickly. Now I’m just relaxing and taking my time, solving it bit by bit and trying to add a personal touch (for instance, I want the background image changing depending on the current weather, and I want background colour of the div with written content to reflect the current temperature).

I hope this helps.

cheers,
Ali

4 Likes

Yeah, that’s a confusing subject. Even if you understand it, there are still a million little things that can go wrong. I think you just slowly learn by trying things out and making mistakes. I also found a few youtube videos that helped explain what was happening a little better. Just search for “getjson” and other stuff like that: this or this.

There are dozens of examples out there. Just try them out, try to change them, try to break them.

Don’t get discouraged. Try a simple API call in a codepen. If it doesn’t work, come back and ask a very specific question about it. I think you’ll find that you get better help from the forum when you ask specific questions about existing code.

1 Like

One thing that really helped for me was to just use Javascript’s XMLHttpRequest Object versus JQuery’s getJSON method. I dunno why but for me it works easier when your just putting in the code to do everything such as sending the GET request.

Another thing I might say to the OP is that APIs can be extra frustrating because they are not standardized, not well documented, and they may get changed with little warning.

Don’t get frustrated. Just keep at it and it will get better. They’ll always be a pain, but they’ll become a manageable pain.

1 Like