I am working with the Spotify Web Playback SDK and an AJAX function fails whenever I put a variable under the data tag/section. However, when I put the contents of the variable under data, it works flawlessly. window.Thingy is equal to '{"uris": ["spotify:track:2xYlyywNgefLCRDG8hlxZq","spotify:track:3FCto7hnn1shUyZL42YgfO"]}'
With variable:
function play(device_id) {
ListPlaylistTracks(); //Gets output of JSON and saves it to window.Thingy
$.ajax({
url: "https://api.spotify.com/v1/me/player/play?device_id=" + device_id,
type: "PUT",
data: window.Thingy, //Variable that doesnt work.
beforeSend: function(xhr){xhr.setRequestHeader('Authorization', 'Bearer ' + _token );},
success: function(data) {
window.dvcID = device_id;
window.PlayBack = true;
}
});
}
Without variable:
function play(device_id) {
ListPlaylistTracks();
$.ajax({
url: "https://api.spotify.com/v1/me/player/play?device_id=" + device_id,
type: "PUT",
data: '{"uris": ["spotify:track:2xYlyywNgefLCRDG8hlxZq","spotify:track:3FCto7hnn1shUyZL42YgfO"]}',
beforeSend: function(xhr){xhr.setRequestHeader('Authorization', 'Bearer ' + _token );},
success: function(data) {
window.dvcID = device_id;
window.PlayBack = true;
}
});
}
Direct comparison:
data: window.Thingy,
vs
data: '{"uris": ["spotify:track:2xYlyywNgefLCRDG8hlxZq","spotify:track:3FCto7hnn1shUyZL42YgfO"]}',
Any help is greatly appreciated, thanks!