Created
December 1, 2016 20:04
-
-
Save lukeshumard/80718821e2864bb1b46ed7f8127eb74c to your computer and use it in GitHub Desktop.
This file contains 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
function checkStatus(response) { | |
if (response.status >= 200 && response.status < 300) { | |
return response; | |
} else { | |
var error = new Error(response.statusText); | |
error.response = response; | |
throw error; | |
} | |
}; | |
function parseJSON(response) { | |
return response.json(); | |
}; | |
var variant_id = 100; | |
fetch('/cart/add.js', { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
credentials: 'same-origin', | |
body: JSON.stringify({"id":variant_id,"quantity":1}) | |
}) | |
.then(checkStatus) | |
.then(parseJSON) | |
.then(function(json) { | |
console.log(json); | |
}) | |
.catch(function(error) { | |
console.log('request failed', error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment