Advertisement
DanielHolm

scrobble with static

Jul 1st, 2013
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Copyright (C) 2013   Daniel Holm <d.holmen@gmail.com>
  3.  *                      Victor Thompson <victor.thompson@gmail.com>
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; version 3.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16.  */
  17.  
  18. // Custom debug funtion that's easier to shut off
  19. function customdebug(text) {
  20.     var debug = "1"; // set to "0" for not debugging
  21.     if (debug === "1") {
  22.         console.debug("Debug: "+text);
  23.     }
  24. }
  25.  
  26. function request() {
  27.     var URL = "https://ws.audioscrobbler.com/2.0/?method=artist.getsimilar&artist=Kiss&api_key=07c14de06e622165b5b4d55deb85f4da";
  28.  
  29.     var xhr = new XMLHttpRequest(); // create new XMLHttpRequest
  30.     var encodedURL = encodeURIComponent(URL); // Make sure whatever you post is URI encoded
  31.     xhr.open(TYPE, encodedURL, true); // only async supported
  32.     xhr.send(); // send the data
  33.  
  34.     xhr.setRequestHeader("User-Agent", "Music-App/0.3");
  35.     xhr.setRequestHeader('Content-Type', 'text/xml');
  36.  
  37.     // did it work?
  38.     if (xhr.readyState==4 && xhr.status === 200) {
  39.         customdebug("Response = " + xhr.responseText);
  40.     }
  41.  
  42.     else {
  43.         // This is very handy for finding out why your web service won't talk to you
  44.         customdebug("Status: " + xhr.status + ", Status Text: " + xhr.statusText + ", Ready state: "+xhr.readyState);
  45.     }
  46.  
  47.     return xhr.responseText;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement