Skip to content

Instantly share code, notes, and snippets.

@mcanv
Created December 1, 2020 09:27
Show Gist options
  • Select an option

  • Save mcanv/e1406a9e710f51e38dbf501fde3effcc to your computer and use it in GitHub Desktop.

Select an option

Save mcanv/e1406a9e710f51e38dbf501fde3effcc to your computer and use it in GitHub Desktop.
Jquery Api Example
$(document).ready(() => {
var post_content = $('#post')
$.ajax({
type: "GET",
url: 'http://localhost:3000/post',
dataType: "json",
beforeSend: () => {
$("#loading").show();
},
success: (result) => {
$("#loading").hide();
if(result.posts.length > 0) {
$.each(result.posts, (key, post) => {
post_content.append('<div class="post-content">'+
'<div class="post-title">'+post.title+" - "+post.created_at+"</div>"+
'<div class="post-body">'+post.body+"</div>"+
'<hr>'+
'</div>'
)
})
} else {
console.log("Can`t find posts")
}
}
})
})
@mcanv

mcanv commented Dec 1, 2020

Copy link
Copy Markdown
Author

You can change the url to your api url and data(result.posts)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment