Skip to content
Update JQuery authored by Joel H's avatar Joel H
......@@ -115,18 +115,35 @@ $.ajax('data/item.json', {
contentType: 'application/json',
cache: false
})
.done(function(response){
console.log(response.items);
let items = response.items;
items.forEach(function(item){
addItem(item.name, item.description, item.price, item.moreInfo);
})
})
.fail(function(request, errorType, errorMessage){
console.log(errorMessage);
})
.always(function(){
console.log("always called");
})
.done(function(response){
console.log(response.items);
let items = response.items;
items.forEach(function(item){
addItem(item.name, item.description, item.price, item.moreInfo);
})
})
.fail(function(request, errorType, errorMessage){
console.log(errorMessage);
})
.always(function(){
console.log("always called");
})
```
```javascript
//ajax POST
let id = $(this).parent().data('id'); //from data-id attribute
$.ajax('data/addToCart.json', {
type: 'post',
data: { id: id}, //these are the things that we send to the server
dataType: 'json',
contentType: 'application/json'
})
.done(function(response){
if(response.message === 'success'){
let price = response.price;
console.log(price);
}
});
```
\ No newline at end of file