Just to give you another way of looking at it. JSON is just a string format, much like WDDX is (although a lot less verbose). Without parsing, it's still just a string.
The manual way of converting JSON to a JS data struct is by calling eval() on it - like so: var data = eval(myJSONString); And you are good to go. Mark On Thu, Jun 18, 2009 at 9:16 AM, Josh Nathanson <[email protected]>wrote: > > It looks like you're getting a string back and it never becomes a > javascript > object. > > If you put dataType:'json' in your ajax params, I believe it will > automatically eval the response for you, which turns the json string > response into a javascript object. You should see this in Firebug as a > clickable green link; when you click it, it should show you the property > values. If it is not clickable, then you have a string rather than an > object. > > This is independent of passing returnformat=json to your cfc. That creates > a json string which gets passed back to the client. However you must do > something in javascript to turn the string into an object; either eval'ing > it manually, or use dataType: 'json' which will do it for you. > > -- Josh > > > > -----Original Message----- > From: James White [mailto:[email protected]] > Sent: Wednesday, June 17, 2009 3:51 PM > To: cf-talk > Subject: Re: CFC and jQuery > > > >1) Add dataType:'json' as an attribute of your ajax call, or use $.getJSON > >2) use Firebug / console.log to examine the response, make sure DATA is a > >valid property of the response JSON > > > >-- Josh > > > > > > > >I am trying to call a query from a CFC using jQuery with the following > code: > > > >$(document).ready( > > function () { > > $.ajax({ > > type: "GET", > > url: "SpellChecker.cfc?method=getTextMemoFields&returnformat=json > > &queryformat=column", > > data: datastring, > > success: > > function(response) { > > var resp = jQuery.trim(response); > > alert(resp); > > } > > }); > > > >}); > > > >When I look at the data inside an alert it looks exactly like it should. > >However, when I try to get to the values inside of it (e.g. resp.DATA) it > is > >always undefined. Do I need to perform an extra step? I appreciate any > >advice I can get on this. > > > >Thanks, > > > >JW > > Josh, > > 1. I already am getting the results back in JSON format using the > returnformat=json parameter. I tried $.getJSON without much success (If > you > know of a good CFC example using $.getJSON, I'd be happy to review it). I > cannot even get results back using it, where as with the $.ajax I get > results, I just can't seem to do much with them but print the whole json > object(i.e. document.write) to a page or display the results in an alert > box. > > 2. I am Firebug and I did verify that DATA is a valid parameter. > Basically > I am returning a db table and putting in JSON format. The code I have > returns the following: > > > {"ROWCOUNT":20,"COLUMNS":["SAVEDVALUE"],"DATA":{"SAVEDVALUE":["blah,blah,bla > h"]}} > > But when I try and access for instance resp.ROWCOUNT, it's undefined. So > basically, I want to know how I can actually get to the values I can only > seem to read. > > Thanks, > > James > > > > > > > > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Want to reach the ColdFusion community with something they want? Let them know on the House of Fusion mailing lists Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:323619 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

