It’s not always my fault

I’ve been planning on learning AngularJS for a while and when I was in Europe I rediscovered some notes that I wrote a couple of months ago with an entrepreneur in Adelaide about a side project we could put together. This project involves using multiple external APIs (including Wikipedia).

I started writing the application on the weekend and ran into some problems with access control errors with JSON. This error happens when a piece of JavaScript is accessing some external file that doesn’t have the same domain as the piece of JavaScript. It’s important for security because it prevents sites sending data somewhere it shouldn’t go without your permission.

If you’re using a public service it’s common for the service provider to give you the ability to access their API by allow HTTP requests to come from other origins using a protocol like CORS.

Wikipedia didn’t do this and I spent maybe 1.5 days wondering why my code was broken when the problem is that I don’t have the ability to access their data from a different origin. I can use jQuery.GetJSON to get JSONP and that works. I might have to get the data using jQuery then pass it to Angular.

In Angular I was trying to use the $http.get method. Unsucessfully.

About Nick

Melbourne based web developer that loves building front-end systems with anything from vanilla JS to React. Infosec student and active learner. Subscribe to the blog

www ·

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.