views:

73

answers:

3

i'm using jquery.getJson() to retrieve a json object created by my php script.

it works if i remove the locations array. however i need the locations array to populate a combobox.

my formatted json is below. any suggestions how i can get this to work with one json query instead of 2.

{ "ContactID" : "1", "CustomerID" : "1", "FirstName" : "john", "LastName" : "smith", "Position" : "General Manager", "ContactNumber" : "234523455", "FaxNumber" : "235235234", "LocationSelected" : "1", "Default" : "default", locations : {0 : { "addressID" : "1" , "description" : "Street Address" }}}

i also tried it like this

{ "ContactID" : "1", "CustomerID" : "1", "FirstName" : "john", "LastName" : "smith", "Position" : "General Manager", "ContactNumber" : "234523455", "FaxNumber" : "235235234", "LocationSelected" : "1", "Default" : "default", locations : [{ "addressID" : "1" , "description" : "Street Address" }]}
A: 

It should work like that. Just make sure that you are using correct mime type.

http://stackoverflow.com/questions/152006/change-mime-type-of-output-in-php

http://stackoverflow.com/questions/477816/the-right-json-content-type

Maybe you should also use quote the locations key

... "locations" : [{ "addressID" : "1" , "description" : "Street Address" }]}

You could also use JSON-functions of PHP to generate the JSON. http://fi2.php.net/manual/en/book.json.php

Epeli
A: 

Hello Ryan, this might solve your problem.. Json retrive and this one too

JustLearn
A: 

some more information.

i can't believe i didnt add this to the question.

my main problem is when i included the array in the json string jquery getjson wouldnt execute the call back function. so i'm guessing the json was malformed and stopping the callback function from executing.

if i dont change any of the jquery code and just adjust the php file to output the json minus the array, the callbackfunction executes and i can access the data.

so i don't see a problem with the jquery it must be the array :S.

Ryan