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?
– Hamurabi Araujo
You have to give more information so we can help... the server language, the code that loads the file, etc...
– Sergio
Already. The folder where the json files are stored is read and write permissible, as they will be automatically updated by another PHP application
– Ronda
@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.
– Ronda
What/how is the line of code that loads that file?
– Sergio
What gives
console.log(typeof data, data);
?– Sergio
@Sergio Typeerror: previouslyActive.classList is Undefined[Learn More]
– Ronda
@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.
– Hamurabi Araujo
try using the full link and not the relative in the URL.
– alan
Test your website link URL/json/slides.json. This works?
– Marcondes
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)
– Ronda