tags:

views:

112

answers:

5

Although i used getJSON in http://jsbin.com/dbJSON/edit i have not been able to connect with any of my own made up data. i tried 4, and the example at Flickr for "cats". Only the latter worked... this is the output:

{assoc: null,assoc.js: null,stub: null,stub.js: null,cat: [object Object]}

i am at that "base", as i did get the image there, but

db.tgu.ca/repsychal/poems/10/0512-g2g/assoc.json
db.tgu.ca/repsychal/poems/10/0512-g2g/assoc.js
db.tgu.ca/repsychal/poems/10/0512-g2g/stub.json
db.tgu.ca/repsychal/poems/10/0512-g2g/stub.js

were all invisible==null! (they are all URL, just put h t t p //: in front ... a restriction on the # of URL in a post)

How do i get "my" data into the page?

A: 

Now that jQuery is more strict on their parsing of JSON data, the document header plays a part now, too.

If you enter your path to assoc.json in the url bar, notice how it serves a binary file that the browser doesn't even know what to do with? Too, if you look at the headers they are text/html; charset=UTF-8, when they should be application/x-javascript; charset=utf-8 (as flickr's is)

One you are serving your file properly, jQuery can read and parse it.

You should be able to enter your path to your json in the URL bar of your browser and see it's output, just as you can with the path to flickr's api.

Dan Heberden
Re: comments:If the file is on dropbox, you don't really have an option unless the file is called 'js', which is retrieved as the right content type. One work around is to parse it yourself:$.post('assoc.json', {},function(data) { var yourNewJsonObject = $.parseJSON(data); }, 'text'};On a side note:As for affecting the server header otherwise, you can specify on servers how to deliver particular files (e.g. set .json to application/x-javascript) or if echo'd by a script you can force it (e.g. <?php header('Content-Type: application/x-javascript'); ?> )
Dan Heberden
A: 

@Dan Heberden

i made a file (same directory) called good.htm This file returns fine in a browser, has good JSON, and STILL gets a null return in the proggy!

gheil.apl
A: 

@Tristram Gräbener ALL files are in the same directory, JSON, htm etc, except for the Flickr stuff which works and is from a jquery example.

gheil.apl
A: 

@Tristram Gräbener ALL files are in the same directory, JSON, htm etc, except for the Flickr stuff which works and is from a jquery example.

gheil.apl
A: 

@Dan Heberden How can one affect the "server" header when the whole directory is on Dropbox - there is no way to change headers. All that can be done is change the extension. i created good.htm with valid JSON which looks usable by a browser but still gets the same null return in the jquery. Ie

$.getJSON("good.htm", function(data){
out=out+"good.htm: "+data + ",";
});

just adds a null to the result (for data).

gheil.apl