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 –