I am using jquery to send an ajax request to perform certain tasks and based on the result of that jquery GET response I am performing some action on Parse Js library.
e.g.
I have created a method like this to send the request.
sendRequest(URL, userId){
return $.ajax({
url: URL + userId,
type: 'GET',
}).fail((responseData) => {
if (responseData.responseCode) {
console.error(responseData.responseCode);
}
});
}
I am using it like this -
sendRequest(URL, userId)
.then(
(data) => {
// Example
// Get some value from data and save it in Parse object
var GameScore = Parse.Object.extend("GameScore");
var gameScore = new GameScore();
gameScore.set("score", 1337);
gameScore.set("playerName", "Sean Plott");
gameScore.set("cheatMode", false);
return gameScore.save();
}
).then(
(changedGameObj) => {
console.log(changedGameObj);
// At this point receiving a parse promise which is not resolved yet.
},
(error) => {
}
);
I know that I am mixing jquery promise and Parse promise but don't know the solution of how to get resolved parse promises because jquery promises gets resolved earlier.
I am quite new to promise in js and please point me where I am wrong.