I knew it must have been something simple-thanks, all of you, for your help.
(You know to be honest I feel like I'm pretty darn good at my job, but
adopting a new paradigm has been a hefty portion of humility!  I have much
to learn.)

 

  _____  

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Christopher Jordan
Sent: Tuesday, February 06, 2007 4:27 PM
To: jQuery Discussion.
Subject: Re: [jQuery] very simple JSON

 

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