Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- search(){
- ajax_call("get_top_tracks");
- }
- search(){
- ajax_call2("artist.gettoptracks", "toptracks")
- }
- ajax_call(method){
- const methods = {
- "get_top_tracks" : {
- method: "artist.gettoptracks",
- data: "toptracks"
- },
- "get_similar" : {
- method: "artist.similar",
- data: "artist"
- },
- 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`;
- fetch(url)
- .then(response => response.json())
- .then(data => this.props.getResponse(data[methods[method]["data"]]))
- .catch(err => alert(err));
- }
- ajax_call2(method, data){
- const url = `http://ws.audioscrobbler.com/2.0/?method=${method}&artist=${this.state.query}&limit=10&api_key=${LAST_FM_API_KEY}&format=json`;
- fetch(url)
- .then(response => response.json())
- .then(data => this.props.getResponse(data[${data}]))
- .catch(err => alert(err));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement