daily pastebin goal
32%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. search(){
  2.     ajax_call("get_top_tracks");
  3. }
  4.  
  5. search(){
  6.     ajax_call2("artist.gettoptracks", "toptracks")
  7. }
  8.  
  9. ajax_call(method){
  10.         const methods = {
  11.                             "get_top_tracks" : {
  12.                                                 method: "artist.gettoptracks",
  13.                                                 data:   "toptracks"
  14.                                             },
  15.                             "get_similar" : {
  16.                                                 method: "artist.similar",
  17.                                                 data:   "artist"
  18.                                             },
  19.         const url = `http://ws.audioscrobbler.com/2.0/?method=methods[method]["method"]&artist=${this.state.query}&limit=10&api_key=${LAST_FM_API_KEY}&format=json`;    
  20.         fetch(url)
  21.         .then(response => response.json())
  22.         .then(data => this.props.getResponse(data[methods[method]["data"]]))
  23.         .catch(err => alert(err));
  24. }
  25.  
  26. ajax_call2(method, data){
  27.         const url = `http://ws.audioscrobbler.com/2.0/?method=${method}&artist=${this.state.query}&limit=10&api_key=${LAST_FM_API_KEY}&format=json`;    
  28.         fetch(url)
  29.         .then(response => response.json())
  30.         .then(data => this.props.getResponse(data[${data}]))
  31.         .catch(err => alert(err));
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top