简体   繁体   中英

JSON file is fetched correctly but fetched data are not displayed in console log

I am trying to do a simple ajax request to retrieve a json file from the server and store it in a javascript object.

I have tried 2 different methods .ajax() method and .getJSON() . Both methods in the Network console seem to fetch the file with result HTTP/1.1 200 OK .

But when I tried to output the received data in the console with console.log(data) nothing shows up.

I have enabled the cross-origin requests in Firefox as I run my code locally and the web server is on a Rpi(Wordpress).

$.ajax({
            url: 'http://192.168.0.227/json/sysC01.json',
            dataType: 'json',
            type: 'GET',
            cache: false,
            crossDomain: true,
            success: function(data){
                console.log(data);
            },

        });


$.getJSON("http://192.168.0.227/json/sysC01.json", function(result){
                console.log(result);
            });

As a first step I want to see that the data are received, which I can't at the moment, and afterwards I would like to store the data in a Javascript object and output them inside a div element with a certain format.

Any suggestion is highly appreciated.

After trying a lot of different things what fixed the issue was running Chrome from the command line with web security disabled.
The relative command:

chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM