Skip to content

Instantly share code, notes, and snippets.

@mattandrews
Created July 30, 2014 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattandrews/fad21a0bfff51fd05a5f to your computer and use it in GitHub Desktop.
Save mattandrews/fad21a0bfff51fd05a5f to your computer and use it in GitHub Desktop.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
function apiRequest(apiKey) {
var that = this;
var deferred = $.Deferred();
this.response = {};
function ajax() {
$.ajax({
url: 'http://internal.content.guardianapis.com/society/2014/jul/14/lady-butler-sloss-stands-down-child-abuse-inquiry?callback=?',
type: 'get',
dataType: 'jsonp',
data: { 'api-key': apiKey },
success: function(data) {
that.response = data;
deferred.resolve(that);
}
});
}
this.getData = function() {
return this.response;
};
// initalise the object
ajax();
return deferred.promise();
}
var api = new apiRequest('gu-hackday-correspondent');
$.when(api).done(function(request) {
var data = request.getData();
console.log(request);
});
</script>
@johnduffell
Copy link

@mattandrews you should probably revisit the example urls you use in this

@johnduffell
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment