Created
May 16, 2013 22:24
-
-
Save lsmith/5595595 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ops = [], i, len; | |
for (i = 0, len = models.length; i < len; ++i) { | |
ops.push(new Y.Promise(function (resolve, reject) { | |
Y.io('save-my-stuff.php', { | |
data: models[i].toJSON(), | |
on: { | |
success: function (id, xhr) { | |
// Maybe you want to JSON parse the responseText first? | |
// Maybe you don't care about the response beyond it being 200? | |
resolve(xhr.responseText); | |
}, | |
failure: function () { | |
reject(new Error("IO error")); | |
} | |
} | |
}); | |
}); | |
} | |
Y.batch.apply(Y, ops).then( | |
function () { | |
console.log('All models saved'); | |
}, | |
function (reason) { | |
console.log('Uh oh. Something went wrong: ' + reason); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment