Home > front end >  Js read native json file through the XMLHttpRequest calls in doubt
Js read native json file through the XMLHttpRequest calls in doubt

Time:12-12

I am going to use the data in json echarts ICONS displayed, so will read operation included the click event of the echarts, specific code is like this:
"'
MyChart. On (' click ', function (params) {
If (params.com ponentType==='series' & amp; & Params. SeriesType==='line') {
Var dataIndex=params. DataIndex;
If (request!=null) {
Var url="./data/cnn4 aapd/metrics_epoch_ "+ dataIndex +" json ";/* json file url, the local local position, if is the path of the server can write server */
Request. The open (" GET ", url, true);/* set the request method and path */
//request. SetRequestHeader (' the content-type ', 'application/json);
//request. OverrideMimeType (" application/json ");
Request. The onreadystatechange=function () {/* XHR object to return information executed after */
If (request. ReadyState==4) {
If (request. Status==200) {/* return status for 200, is the data acquisition success */
Var json=json. Parse (request. The responseText);
//start reading data manipulation behind
"'
Then I run to find need to click twice to read the new data come in, if it is at first click is no data for the first time, and then click again will, according to the data read in my setoption operation is followed by the front, and then draw immediately after reading data, access to the Internet to find the data found that may be because the xmlhttprequest than simple request will start a options preview request, but I've put the custom head all annotations in the get the result or not, the Internet also can not find the block request returns data for the first time, want to ask you what's the solution? To click only once can out graphics,

CodePudding user response:

Use the browser F12 see Network

CodePudding user response:

Reading local json should not have the options, click inside the debugger on whether other errors
  • Related