我對如何處理維基百科API調用中的反應有點困惑。我一直運行到這個錯誤:維基百科上的CORS錯誤API
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource(...)
現在,我運行在提交表單的動作,形式採取的形式輸入值,並插入到這一點維基百科的API網址。我曾嘗試使用JSONP,但我真的不想使用它,因爲我聽說它是超級哈克。
動作/ index.js
import axios from 'axios';
const WIKI_URL = "https://en.wikipedia.org/w/api.php?action=query&format=jsonp&list=search&titles=";
const FETCH_ARTICLES = 'FETCH_ARTICLES';
export function fetchArticles(term) {
const url = `${WIKI_URL}${term}`;
const request = axios.get(url);
return {
type: FETCH_ARTICLES,
payload: request
}
如果有必要我可以肯定地添加更多的代碼,但是從我所知道的,這是問題所在。編輯:如果我不得不使用JSONP,我仍然無法使用。我相信axios不支持JSONP,會不會有更好的庫使用?爲什麼有些API具有跨源參考錯誤,而其他API則不?
看起來像其他一些人也有同樣的問題https://github.com/mzabriskie/axios/issues/191 –