I haven't been able to find the answer so I made a temporary workaround - and I can't use that in the end file.
when the json array is directly in my javascript file, everything works correctly.
Moving it to it's own file and then using $.getJSON returns nothing. Even alert("hi") inside doesn't show.
structure of json array in file name text.json :
var settable = {"playerinfo" : [{"seated": "player1","name": "Mack","stuff": "5025"},
{"seated": "player2","name": "Ahle","stuff": "5030"}]);
var hand = {"hands" : [{"carda": "aa", "cardb": "bb"}, {"carda" : "cc", "cardb": "cc"}]);
to be used in something like:
$("#div").text(settable.playerinfo[i].name);
THANKKK YOUUUUU!
And the next step is filling the "aa" etc with AJAX
how do i get this?
use json_decode
you have invalid json. Replace the last )
with }
If that is what your text file looks like, then You are sending javascript, not json. Format your json to look something like this:
{
"settable" : {
"playerinfo" : [
{
"seated": "player1",
"name": "Mack",
"stuff": "5025"
},
{
"seated": "player2",
"name": "Ahle",
"stuff": "5030"
}
]
},
"hand" : {
"hands" : [
{
"carda": "aa",
"cardb": "bb"
},
{
"carda" : "cc",
"cardb": "cc"
}
]
}
}
Also, you should give an error handler to your getJSON that will tell you what the problem is, which in this case is a JSON syntax error.