2

When I upload my project to the FTP server the JSON file I'm pulling data from is not working properly. but when I run the program from XAMP, my local server, it runs perfectly fine. I noticed the JSON is not being read correctly by inspecting the element on the FTP server. This is what it looks like:

This is the picture where the json is not working

Here is the app being ran off my local server, where i inspect the element. This is currently working:

This is the working example

This is how I am accessing the file in my code:

$.ajax({
        url: 'includes/js/jsons/' + location_name + '.json',
        datatype: 'json',
        success: function(parsed_json){
            // doing stuff
});

Any ideas on why this could be messing up?

Note: I don't think that my JSON file is being recognized as a JSON file but rather a HTML doc or something.

Foemilod
  • 125
  • 1
  • 2
  • 12
  • Is the file transformed when you send the file by FTP? Have you configured Filezilla to keep the file unchanged when sending? – A.L Dec 14 '14 at 03:21
  • Not to my knowledge. I just copy and paste from my htdocs file to the filezilla – Foemilod Dec 14 '14 at 03:22
  • If you open this JSON file direcly (locally and remotely) with your browser, do you see any difference? – A.L Dec 14 '14 at 03:24
  • Nope, it looks exactly the same. I went directly to the file location on the FTP server using the address bar – Foemilod Dec 14 '14 at 03:29

2 Answers2

2

I think this FileZilla changes linebreaks as default and this cause the problem, follow this link to change this behaviour and test again: How can I stop Filezilla changing my linebreaks?

Community
  • 1
  • 1
Ali Javadi
  • 31
  • 1
  • 3
0

Alrighty, so the problem was in fact that the json file was being read as a string and not a json despite having set the datatype to json. To remedy this problem I had to parse the json file as a json file through this line of code

$.ajax({
    url: 'includes/js/jsons/' + location_name + '.json',
    datatype: 'json',
    success: function(parsed_json){
        var parsed_json = $.parseJSON(parsed_json);
});

I also edited a the settings in the FTP process where it will only upload as binary rather than auto.

If you have the same problem, try both. Follow the link provided by Ali Javadi if the parse json does not work.

Foemilod
  • 125
  • 1
  • 2
  • 12