Created
July 30, 2014 13:11
-
-
Save mattandrews/fad21a0bfff51fd05a5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mattandrews you should probably revisit the example urls you use in this