Skip to content

Instantly share code, notes, and snippets.

@data-doge
Created April 6, 2015 06:47
Show Gist options
  • Select an option

  • Save data-doge/015a4a9fe96ae1b0f649 to your computer and use it in GitHub Desktop.

Select an option

Save data-doge/015a4a9fe96ae1b0f649 to your computer and use it in GitHub Desktop.
ajax example geordi
$(document).ready(function() {
$('#new-item-form').on('submit', function (e) {
e.preventDefault();
var data = $(e.target).serialize();
$.ajax({
type: 'POST',
url: '/api/items',
data: data,
success: function (res) {
console.log(res);
var htmlString = "<li>" +
"<h2>" + res.name + "</h2>" +
"<h3>$" + res.price + "</h3>" +
"<p>" + res.description + "</p>" +
"</li>";
$('#items').prepend(htmlString);
},
error: function () {
console.log("error");
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment