Adding An Item
Goals
Overview
Steps
Step 1
$('#add-form').on('submit', function(event) { var itemDescription = event.target.itemDescription.value alert('trying to create a new item with a description ' + itemDescription) })Step 2
event.preventDefault()Step 3
var creationRequest = $.ajax({ type: 'POST', url: "http://listalous.herokuapp.com/lists/YOUR-LIST-NAME-HERE/items", data: { description: itemDescription, completed: false } })Step 4
creationRequest.done(function(itemDataFromServer) { addItemToPage(itemDataFromServer) })
Explanation
$('#add-form').on('submit', function(event) { event.preventDefault() var itemDescription = event.target.itemDescription.value var creationRequest = $.ajax({ type: 'POST', url: "https://listalous.herokuapp.com/lists/YOUR-LIST-NAME-HERE/items", data: { description: itemDescription, completed: false } }) creationRequest.done(function(itemDataFromServer) { addItemToPage(itemDataFromServer) }) })
Next Step:
Go on to Marking An Item As Complete