JSON loads on localhost but not in production

Asked

Viewed 180 times

1

I’m developing a website project that uses JSON files to feed dynamic data. In localhost, using XAMPP, the data is loaded but when I go up to a production server the page does not read the JSON files, it returns NULL where the data should appear. The entire project, html, js, css, json, images, etc., are in the same domain. Is there some form of server configuration that could be causing this? I know there is a limitation if the JSON file is in a different domain (cross Domain). This is not the case.

The HTML is like this:

<div id="slider">
    <div class="slides" id="carregaSlides">
    </div>
</div>

In the JS is like this:

function carregaSlides() {
    loadSlide ="";
    //$("#carregaSlides").html("");
    $.getJSON('json/slides.json', function(data){

        $.each(data, function(key, val){
            loadSlide += "<div class='slider'><div class='legend'></div><div class='content'><div class='content-txt'></div></div><div class='image'><img src='slides/"+ val.slide +"' class='imgSlide'></div></div>";
            $("#carregaSlides").html(loadSlide);
        });

});

}
  • Already checked read permissions of files?

  • You have to give more information so we can help... the server language, the code that loads the file, etc...

  • Already. The folder where the json files are stored is read and write permissible, as they will be automatically updated by another PHP application

  • @Sergio, it’s a simple HTML application, one page only. Locally it works well. It feeds a div with JSON data. When I put it into production it doesn’t happen. It’s like I’m not allowed to read the file, as Hamurabi said. That’s not the case. I already checked permissions in the folder.

  • What/how is the line of code that loads that file?

  • What gives console.log(typeof data, data);?

  • @Sergio Typeerror: previouslyActive.classList is Undefined[Learn More]

  • @Ronaldodantas, a stupid question, but just to be sure: is he finding the file or is he giving 404? Just to make sure you’re not giving problems with the relative links.

  • try using the full link and not the relative in the URL.

  • Test your website link URL/json/slides.json. This works?

  • Friends, I solved it! I talked to one of the network admins here at the office and he gave me what is a security restriction. He suggested that instead of using . json file, use a . php file that returns data with the structure of a json file, as needed. It worked. I appreciate everyone’s help. There in the code I exchanged $.getJSON('json/slides.json', Function(data) for $.getJSON('json/slides.php', Function(data)

Show 6 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.