Skip to content

Instantly share code, notes, and snippets.

@mojaray2k
Created February 3, 2016 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mojaray2k/a8c051f473ac63ea61ff to your computer and use it in GitHub Desktop.
Save mojaray2k/a8c051f473ac63ea61ff to your computer and use it in GitHub Desktop.
var getPosts = new Promise(function(resolve, reject) {
$.ajax({
url: ajaxURL + '/posts',
method: 'GET',
success: function( res ){
if (res.length) {
resolve(res);
}
else {
reject(Error("No Posts"));
}
}
});
});
getPosts.then(function(res){
$.each( res, function( key, value ){
$( '#your-wrapper' ).append( '<h2>' + value.title.rendered + '</h2>' );
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment