[object Object] error

I’m on the Local Weather Project but I’m running into an [object Object] error and the internet isn’t explaining the issue very well. Could someone please explain what the problem is? Please tell me it isn’t because I have two ajax requests!

Do you have your code somewhere?

Whoops, that would be helpful wouldn’t it? I added the codepen to the original message.

First of all it alerts [object Object] because the error is an object and the alert function can only output a string. Now, if you console.log the error you will see the following error message: Invalid API key. Please see http://openweathermap.org/faq#error401 for more info.

EDIT: If you got an API key from openweathermap you can use it like this:

data: {
  'APPID': 'YourAppIdHere'

Oh, it needs a key. Well that should solve the issue. Thanks!

Extra credit question: can, and should, I just console.log the error instead of making them alerts? Or maybe add a console.log to the error function so I get an alert and then know to just check the log?

I find alerting something very annoying when you are developing. Especially on Codepen where it randomly refreshes.

Besides, usually an API will return an object (JSON), so you will only be able to see it in the console. Also if you are developing you will most likely want to keep the console open (to see what the API returns). But do whatever you like, if it is easier for you to alert and then log it, then do that.

1 Like

I’ll give it consideration. I’m not a fan of the constant refresh codepen does so I always turn it off, which keeps me from experiencing an alert spam issue since the code only runs when I tell it to. (Although this is the first time it’s triggered too >.<)

Thanks for the help. Just waiting for the key to be activated and I should be good to go.

1 Like

It’s still not working. I tried using the data method you suggested and even tacked the key onto the end of a url like it is set up in the code right now and I’m still getting a 404 error. But if I put the url into my browser it works fine.

Any ideas/suggestions?

Oh my bad, forgot to mention: there should be http:// in front of the API url.

1 Like

Because the browser adds it automatically but javascript won’t. DERP.

Works perfectly now. Rest of the project is pretty much just CSS :cry: and some basic functions