Created
December 1, 2020 09:27
-
-
Save mcanv/e1406a9e710f51e38dbf501fde3effcc to your computer and use it in GitHub Desktop.
Jquery Api Example
This file contains hidden or 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
| $(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") | |
| } | |
| } | |
| }) | |
| }) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can change the url to your api url and data(result.posts)