Paul, you forgot to eval the JSON string. Andy (or anyone, really) can correct me if I'm wrong, but even when using the $.get method you have to eval the JSON that gets returned.

For instance:
 {"TRUCK":"INVALID", "ISVALID":false}

Is valid. But you need to have JavaScript evaluate the string to turn it into an object (which can be thought of as a structure)

If you eval the above like this:
 var MyData = eval("(" + response + ")");

You should then be able to say:

   alert(MyData.Truck);

...and get the value "Invalid" as a result.

Does that help? I remember struggling with this stuff too, so feel free to shout if this doesn't work or make sense.

Chris

Paul wrote:

I'm sure this is something simple but I'm going nuts. I'm simply trying to access JSON data that is being returned by an ajax call. This is my first attempt to play with JSON, so here we go...

$.get("cfc/scalehouse.cfc?method=validateTruckCode&truck_code=" + $("input").val(),

function(response){

$('#content').html(response); //THIS OUTPUTS {"TRUCK":"INVALID","ISVALID":false}

alert(response.TRUCK); //THIS ALERTS "undefined"---shouldn't it alert "INVALID"?

         });

Can you tell what I've done wrong?

Thanks...

Paul

------------------------------------------------------------------------

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

--
http://www.cjordan.info

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to