Skip to content

Instantly share code, notes, and snippets.

@gracekrcx
Created September 8, 2019 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gracekrcx/4430cb8df893669b12d25242ec93bf3b to your computer and use it in GitHub Desktop.
Save gracekrcx/4430cb8df893669b12d25242ec93bf3b to your computer and use it in GitHub Desktop.
apiExample
apiExample = ()=>{
const API_URL = '/path';
fetch(API_URL,{
method:'post'
headers: {
'content-type': 'application/json'
},
}).then(function(response){
return response.json()
}).then(data=>{
if(data.code == '200'){
// 200 處理邏輯
}else{
// 非 200 處理邏輯
}
}).catch(error=>{
// error 處理邏輯
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment