function getDeviceToken() {
$.ajax({
url: 'url',
type: 'post',
data: {
test: 'test'
}
})
.done(function (res) {
console.log(res);
})
.fail(function (error) {
var data = error.responseJSON;
if (data.error) {
if (data.error == 'authorization_pending') {
setTimeout(getDeviceToken(), 5000);
}
}
});
}