Forums

AJAX Request for JSON File

I am trying to do an ajax request for a JSON file in a folder on python anywhere. I have tested the code locally (firefox) and I can get the JSON file data and use it on a Webpage or see it on the console. I am using DJANGO, so the page is served up from my view. Using developer tools in Firefox, the network tab, it appears that some or all of the data are transferred (1.7 KB of 50 KB as seen in pythonanywhere, I assume it is compressed). Is DJANGO preventing this request from accessing this file. If so, what is the solution. Thank you for any help you may provide.

function makeProfile(){
    console.log("test");
    $.getJSON("files/home/kpilgrim1504/lake_model_2/profile/lakeprofile.json", function(data) {
         console.log("test");
     var profilelength = data.temps[0].d1h8.length;
     console.log(profilelength);
     var profilepoint = "";

     for (i = 0; i < 17; i++) {
       var depthindex = 'p' +i;
       profilepoint = data.temps[0].d1h8[i].p0;

     };
     $("#jsondata").text(depthindex);

   });
}

Look in your error and server logs to see if there's an error associated with the failed request. Also check the actual content of the response in the developer tools to see what you're actually getting back from the the server.