Created
April 6, 2015 06:47
-
-
Save data-doge/015a4a9fe96ae1b0f649 to your computer and use it in GitHub Desktop.
ajax example geordi
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(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