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:360220
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm