Last active
March 23, 2020 21:37
-
-
Save eduzera/972215c5f8de6f1ebff17cb13389cd40 to your computer and use it in GitHub Desktop.
posts example with jquery
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
function makePost(data){ | |
var url = "/api/v1/posts" | |
$.ajax({ | |
type: "POST", | |
url: url, | |
data: { | |
name: 'edu', | |
age: '33' | |
}, | |
dataType: "json", | |
success: function (response) { | |
console.log(response) | |
getPosts() | |
} | |
}); | |
} | |
function getPosts() { | |
var url = "/api/v1/posts" | |
$.ajax({ | |
type: "GET", | |
url: url, | |
data: "data", | |
dataType: "json", | |
success: function (response) { | |
renderPosts(response.html) | |
} | |
}); | |
} | |
function renderPosts(response) { | |
$('#posts').html(response) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment