【发布时间】:2019-10-13 17:58:18
【问题描述】:
我正在从客户端进行 API 调用,但等待 4 分钟后失败。
但是当我在 Oracle SQL Developer 中运行相同的查询时,它会花费相同的时间,但会在那里显示数据。
我在前端使用 ReactJS,在后端使用 nodeJS。
那么谁能告诉我我应该在前端更改什么,以便 API 调用不会失败并可以呈现数据。
在 Postman 中也抛出错误 - 等待很长时间后无法得到响应。
componentDidMount() {
// debugger;
// event.preventDefault();
axios.get(`http://localhost:4000/api/AMS/country`)
.then(response => {
// console.log(response);
const country_Claim_Type = response.data;
this.setState({ country_Claim_Type
});
console.log('data fetched');
return axios.get(`http://localhost:4000/api/AMS/countryDollar`)
}).then(response => {
// console.log(response);
const country_Claim_Dollar = response.data;
this.setState({ country_Claim_Dollar
});
console.log('data fetched');
return axios.get(`http://localhost:4000/api/AMS/claimQuarter`)
}).then(res => {
const claims = res.data;
let claim = [];
let puru = [];
claims.forEach(element => {
claim.push(element.COUNT);
puru.push(element.USD);
});
this.setState({
Data: {
labels: ['FY19 Q1[NOV-JAN]','FY19 Q2[FEB-APR]','FY18[SEP-NOV]'],
datasets:[
{
label:'',
data: claim ,puru,
backgroundColor:[
'rgba(255,105,145,0.6)',
'rgba(155,100,210,0.6)',
'rgb(63, 191, 191)'
]
}
]
}
});
return axios.get(`http://localhost:4000/api/AMS/claimType`)
}) .then(barGraph => {
const claims = barGraph.data;
let claimcount = [];
let claimtype = [];
claims.forEach(element => {
claimcount.push(element.COUNT);
claimtype.push(element.CLT_NAME);
});
this.setState({
Claim_Type: {
labels: claimtype,
datasets:[
{
label:'',
data: claimcount ,
backgroundColor:[
'rgba(255,105,145,0.6)',
'rgba(155,100,210,0.6)',
'rgb(255, 0, 64)',
'rgb(191, 255, 0)',
'rgb(0, 255, 255)',
'rgb(128, 0, 255)'
]
}
]
}
});
return axios.get(`http://localhost:4000/api/AMS/claimCountry`)
}).then(countryList => {
const claims = countryList.data;
let claimcount = [];
let country = [];
var coloR = [];
const percent = "%";
// let claimvalue = [];
let claimTotal = 0;
var dynamicColors = function() {
var r = Math.floor(Math.random() * 255);
var g = Math.floor(Math.random() * 255);
var b = Math.floor(Math.random() * 255);
return "rgb(" + r + "," + g + "," + b + ")";
};
claims.forEach(element => {
claimTotal+=element.COUNT;
});
claims.forEach(element => {
claimcount.push(parseFloat((element.COUNT/claimTotal)*100).toFixed(2));
// claimvalue.push(element.USD);
country.push(element.COUNTRY);
coloR.push(dynamicColors());
});
this.setState({
country_claim: {
labels: country,
datasets:[
{
label:'ClaimCounts',
data: claimcount,
backgroundColor: coloR
}
]
}
});
return axios.get(`http://localhost:4000/api/AMS/claimDollar`)
}).then(res => {
const claims = res.data;
let dollar = [];
claims.forEach(element => {
dollar.push(element.USD);
});
this.setState({
dollar_value: {
labels: ['Q1','Q2','FY18'],
datasets:[
{
label:'',
data: dollar ,
backgroundColor:[
'rgba(255,105,145,0.6)',
'rgba(155,100,210,0.6)',
'rgb(63, 191, 191)'
]
}
]
}
});
})
}
【问题讨论】:
-
请添加相关代码和错误信息。另见How to create a Minimal, Reproducible Example
-
错误信息是什么,它来自哪里?
-
错误是 GET localhost:4000/api/AMS/claimQuarter net::ERR_EMPTY_RESPONSE