0
handleLoginClick(event) {
var apiBaseUrl = "http://localhost:8000/api-token-auth/";
var self = this;
var payload={
"email": "myusername",//this.state.username,
"password": "mypassword"//this.state.password
};
axios.post(apiBaseUrl, payload)
.then(function (response) {
alert('success')
})
.catch(function (error) {
alert('NO') . // <----- always reaches here.
console.log(error);
});
}
由于某些原因,此代码总是失败并提醒'NO'。我正在尝试的端点是有效的,并且可以通过curl中的这些参数进行访问。任何想法有什么不对?Axios总是因为某种原因失败
我有:
import axios from 'axios';
控制台输出:
XMLHttpRequest cannot load http://localhost:8000/api-token-auth/. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
什么是控制台的错误,它给 –
后期编辑,以反映从浏览器 – JasonGenX
API请求需要与访问控制允许来源头来valided,你需要的,如果你使用的是从你的API –