Skip to content

Instantly share code, notes, and snippets.

@lipelopeslage
Created June 28, 2016 02:40
Show Gist options
  • Save lipelopeslage/e0de42ac2b8cdb8af17fe4a9f5408372 to your computer and use it in GitHub Desktop.
Save lipelopeslage/e0de42ac2b8cdb8af17fe4a9f5408372 to your computer and use it in GitHub Desktop.
Ajax example with Promisse.
function asyncFunc() {
return new Promise(
function (resolve, reject) {
$.get('https://httpbin.org/geta', function(res){
resolve(res);
}).fail(function(res){
reject(res.responseText);
});
});
}
asyncFunc()
.then(value => { console.log('success:', value) })
.catch(error => { console.log('error:', error) });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment