Advertisement
Guest User

Untitled

a guest
May 2nd, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. document.addEventListener("DOMContentLoaded", function(event) {
  2.     function httpGetAsync(theUrl, callback)
  3.     {
  4.         var time = new Date().getTime() / 1000;
  5.         var nonce = randomString(32);
  6.         var xmlHttp = new XMLHttpRequest();
  7.         xmlHttp.open("GET", theUrl, true);
  8.         var params = JSON.stringify(
  9.             {oauth_consumer_key:'TKk4q4d0R_ChTSTgfJe__g'},
  10.             {oauth_token:'nXF2cUc5nwnGh06V8W8ZmIAt2B5WPzUY'},
  11.             {oauth_signature_method:'hmac-sha1'},
  12.             {oauth_signature:'WkVTrSYhI0oChU-uyvvuldJPK0A'},
  13.             {oauth_timestamp:time},
  14.             {oauth_nonce:nonce}
  15.  
  16.         );
  17.        
  18.         xmlHttp.setRequestHeader("Content-type", "application/json; charset=utf-8");
  19.         //xmlHttp.setRequestHeader("Content-length", params.length);
  20.         xmlHttp.setRequestHeader('Access-Control-Allow-Origin','*');
  21.         //xmlHttp.setRequestHeader("Connection", "close");
  22.         xmlHttp.onreadystatechange = function() {
  23.             if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
  24.                 alert(http.responseText);
  25.         };
  26.         xmlHttp.send(params);
  27.     }
  28.  
  29.     var randomString = function(length) {
  30.         var text = "";
  31.         var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  32.         for(var i = 0; i < length; i++) {
  33.             text += possible.charAt(Math.floor(Math.random() * possible.length));
  34.         }
  35.         return text;
  36.     };
  37.  
  38.     httpGetAsync('https://api.yelp.com/v2/search?term=food&location=San+Francisco');
  39.  
  40.     function something (text){
  41.         console.log(text);
  42.     }
  43.  
  44. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement