这是我第一次使用axios,遇到了一个错误。
axios.get(
`http://someurl.com/page1?param1=1¶m2=${param2_id}`
)
.then(function(response) {
alert();
})
.catch(function(error) {
console.log(error);
});
使用正确的 url 和参数,当我检查网络请求时,我确实从服务器得到了正确的答案,但是当我打开控制台时,我发现它没有调用回调,而是捕获了错误。
错误:网络错误
堆栈跟踪:
创建错误@http://localhost:3000/static/js/bundle.js:2188:15 http://localhost:3000/static/js/bundle.js:2188:15处理错误@http://localhost:3000/static/js/bundle.js:1717:14 http://localhost:3000/static/js/bundle.js:1717:14
如果使用 NodeJS 创建 API
Your Express app needs to use CORS (Cross-Origin Resource Sharing). Add the following to your server file:
// This should already be declared in your API file
var app = express();
// ADD THIS
var cors = require('cors');
app.use(cors());
为了更全面地了解 CORS,请阅读关于 CORS 的 Mozilla 文档 https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)