【发布时间】:2018-12-11 00:23:12
【问题描述】:
我有一个 axios 调用来从数据集中获取 UPC。如果成功了我就做点什么,如果没有找到,再次调用axios进行POST。
这就是我现在所拥有的,但是当它在尝试运行 get 时出错 (404) 时,我得到一个 422 错误。
axios.get('http://localhost:3000/api/products/findOne', {
"params": {
"filter": {
"where": {
"upc": product.upc
}
}
}
}).then(response => {
// UPC Found
}).catch(function(error) {
// UPC Not found
// Post UPC
axios.post('http://localhost:3000/api/products', {
//axios stuff here
}).then((response) => {
console.log(response);
}).catch((error) => {
console.log(error);
});
});
我根本不相信我这样做是正确的...输入?
【问题讨论】:
标签: javascript ajax post get axios