Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. function getStuff(num, onContents){
  2. $.getJSON('http://whateverorigin.org/get?url=' + encodeURIComponent('http://catholic.com/api-radio/' + num) + '&callback=?', function(data){
  3. //call the oncontents callback instead of returning
  4. onContents(data.contents);
  5. });
  6. }
  7.  
  8. //when calling getstuff, pass a function that tells what to do with the contents
  9. getStuff(6387, function(contents){
  10. window.GlobalVar = contents;
  11. });
  12.  
  13. var NewVar = window.GlobalVar;
  14. alert(NewVar);
  15.  
  16. getStuff(6387, function(contents){
  17. // the following statement will assign the value of 'contents' to the global variable 'GlobalVar'
  18. window.GlobalVar = contents;
  19. });
  20.  
  21. var NewVar = window.GlobalVar;
  22. alert(NewVar);
  23.  
  24. function getStuff(num) {
  25. $http.jsonp('http://whateverorigin.org/get?url=' + encodeURIComponent('http://catholic.com/api-radio/' + num) + '&callback=JSON_CALLBACK')
  26. .success(function (contents) {
  27. $scope.shows = contents;
  28. });
  29. };
  30. getStuff(6387);
  31.  
  32. .success(function (response) {
  33. var result = angular.fromJson(response.contents);
  34. $scope.shows = result.shows;
  35. });
  36.  
  37. <ul>
  38. <li ng-repeat="show in shows">{{ show.title }}</li>
  39. </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement