Codepen throws error on weather app


I am finished with my weather app, it’s working fine on safari/ff, I was trying to upload it on codepen in order to share it on the forum but once I put up the js code it returned this error:

“Oh no! You clicked a broken link in a Pen!
The author of this Pen may have linked to the wrong URL, or there might be a typo somewhere.”

You can see what’s going on here:

I really can’t track down the error since everything is working fine on browsers, I suppose it’s something related to codepen and using external apis, but I think I followed all the good practices I could find.

Can you spot some mistake I can’t?


Hi @Bagongo…I suggest adding console.log calls to write the URL’s you are constructing to the console. You can then cut and paste them into another browser window to validate that they are correct. I can see that your main screen is displayed for under a second before the 404 is thrown. This makes me assume that the issue is with the URL’s you are constructing to retrieve current weather conditions. I hope this helps out.

Thank you @jdmedlock. I think that’s the issue, but if I paste the urls into a new page I get exactly the data expected. No errors traceable this way… Any other idea?

Codepen does this from time to time for reasons i haven’t quite sussed out yet. The easy fix is to wrap all of the code in the document’s ready event handler, like so:

$(document).ready(function() {
// all of your code here

You’re going to find another problem with your code as is, though. The issue is that your browser’s security policy won’t run code downloaded from another site without some special unicorn magic. You can use the same service, but you’ll need to also use a CORS proxy. This most popular these days is, and you want to tack it onto the front of your URL
1 Like

You might also try exporting to a native HTML page and running from within your browser using Developer tools so you can debug.

Thanks for the help guys!

@PortableStick I tried to wrap the code with $(window).on(“load”, function(){} but it didn’t work. Instead your
$(document).ready(function() {}) suggestion did the trick! Thank you!

Ah. The way you’d typically see it done with vanilla JS is

window.onload = function() {
// code here

Thanks @PortableStick. I totally missed this. Good work!