Skip to content

Instantly share code, notes, and snippets.

@eduzera
Last active March 23, 2020 21:37
Show Gist options
  • Save eduzera/972215c5f8de6f1ebff17cb13389cd40 to your computer and use it in GitHub Desktop.
Save eduzera/972215c5f8de6f1ebff17cb13389cd40 to your computer and use it in GitHub Desktop.
posts example with jquery
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