Open xgqfrms-GitHub opened 6 years ago
componentDidMount() {
// 'Access-Control-Allow-Origin' header
// set the request's mode to 'no-cors'
// const url = `http://10.1.5.31:8081/http/manage/admin?{"Admin":"report","Action":"GetAllLoad","WriteType":"json"}`;
const url = `http://localhost:7777/info/`;
const init = {
method: 'GET',
headers: {
'Accept': 'application/json',
"Access-Control-Allow-Origin": "*",
'Content-Type': 'application/json'
},
mode: 'no-cors'
};
const request_url = new Request(url, init);
fetch(request_url)
.then((response) => response.json())
.then((json)=> {
console.log(`json = ${json}`);
console.log(`json.length = ${json.length}`);
/* json = json.Info;
console.log(`json.Info = ${json.Info}`);
console.log(`json.Info.length = ${json.Info.length}`); */
const datas = json.map(
(data) => {
console.log(`data`, data)
return data;
}
);
console.log(`datas = ${JSON.stringify(datas)}`);
return datas;
})
.then((datas)=> {
console.log(`datas new = ${JSON.stringify(datas)}`);
return this.setState({
datas: datas
});
});
}
--disable-web-security
Chrome CORS
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --user-data-dir=D:\Chrome
"C:\Program Files (x86)\Google\Chrome\Application"
Chrome & CORS
https://www.cnblogs.com/xgqfrms/
http://www.cnblogs.com/xgqfrms/p/8327473.html
http://www.cnblogs.com/linda586586/p/4351452.html