Well, I actually had to look at the result set from the CFC, to know which
columns in the result.DATA array were the right ones.  There's also a
result.COLUMNS that gives you the list of column names, so for me
result.DATA[0][2] was the name and the Acres field was in
result.DATA[0][12] - hence why those are there.

Basically what you are getting are two arrays from the CFC, that are both
stored in the result object.  there is the COLUMNS array and the DATA
array, so you need to know which item of each you are trying to access.  So
in my case, I am setting the values of a form, based on what the request is.

As with all AJAX requests, Chrome Dev Tools, IE Dev Tools and Firebug are
your friends.  Throw a console.log(result); in there, open up whatever tool
of choice and inspect what the console is telling you.  From that assign
the data to whatever input/output containers you have.

Rob

On Fri, 6 Mar 2015 at 14:15 Torrent Girl <[email protected]> wrote:

>
> Thanks Rob
>
> I recreated your example with the cfartgallery data source in CF.
>
>
> Here is my method:
>
> <cffunction name="data" access="remote" returntype="query">
>
> <cfset var q = ''/>
>
> <cfquery name="q" datasource="cfartgallery">
> select * from artists
> </cfquery>
>
>  <Cfif q.recordcount eq 0>
>         <Cfset q = queryNew("artistID,firstName")>
>     <Cfset queryAddRow(q,1)/>
>     <Cfset q.artistID = 0/>
>     <Cfset q.firstName=''/>
> </cfif>
>  <Cfreturn q/>
> </cffunction>
>
>
> Here is my call:
>
>
> <script>
> $.ajax({
>                         type: 'get',
>                         url: 'data.cfc',
>                         data: {
>                             method: 'data',
>
>                         },
>                         dataType: 'json',
>                         success: function (result) {
>                                 $("#artistID").val(result.DATA[0][2]);
>                                 $("#firstName").val(result.DATA[0][12]);
>
> }
> });
>
>   </script>
>
>
>
> So how do I output the data on the page?
>
>
>
> >Well, I don't know what standardiseCfQueryJSON does, but here's what I do:
> ><cffunction name="listFields" displayname="List Fields"  access="remote"
> >returntype="query">
> ><cfargument name="growerID" displayName="Grower ID" type="numeric" hint="I
> >am the Grower ID" required="true" />
> >
> ><cfset var q = ''/>
> > <cfquery name="q">
> >Select * from `field`
> >where g_id = <cfqueryparam value="#arguments.growerid#"
> >cfsqltype="cf_sql_integer" />
> >order by fieldname
> ></cfquery>
> > <Cfif q.recordcount eq 0>
> ><Cfset q = queryNew("f_id,FieldName")>
> ><Cfset queryAddRow(q,1)/>
> ><Cfset q.f_id = 0/>
> ><Cfset q.fieldname=''/>
> ></cfif>
> > <Cfreturn q/>
> ></cffunction>
> >
> >and then on the calling page:
> >
> >  $.ajax({
> >                        type: 'get',
> >                        url: '/cfcs/field/fields.cfc',
> >                        data: {
> >                            method: 'fieldData',
> >                            fieldID: $("#fielder").val()
> >                        },
> >                        dataType: 'json',
> >                        success: function (result) {
> >                                $("#fieldname").val(result.DATA[0][2]);
> >                                $("#acres").val(result.DATA[0][12]);
> >                                $("#911num").val(result.DATA[0][6]);
> >}
> >});
> >
> >You are taking a Query and putting it in a struct.  I would either leave
> it
> >a query (as Above) or put it in an array
> >
> >HTH,
> >
> >Rob
> >
> >
> >
> >
> >On Fri, 6 Mar 2015 at 10:20 Torrent Girl <[email protected]> wrote:
> >
> >>
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:360221
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to