4

I'm close on this one.

I am calling a CFC to query some data:

$.ajax({
    
    dataType: 'json',
    data:  {
                customer_name: $('##customer_name').val()
            },
    url: "cfcs/customers_lookup.cfc?method=getAddress&returnformat=query",
    beforeSend: function(){
        $('.loader').show();
    },
    complete: function(){
         $('.loader').hide(3000);
        console.log(JSON.stringify(data));
    },
    success: function(response) {
                       $.each(response.DATA, function(i, row){
                        // get value in first column ie "description"
                        var address = row[0];
                        
                        
                        // append new option to list
                        $("##customer_address").append(address);
                       })
                    }    
});

In my CFC, I query the database as follows:

<cffunction name="getAddress" access="remote" returnType="query">
    <cfargument name="customer_name" type="any" required="true">

    <!--- localize function variables --->
    <cfset var addressDetail = "">
    <cfoutput>
    <cfquery name="addressDetail" datasource="#datasource#">
        SELECT address1, address2
        FROM   customer_table
        <!--- adjust cfsqltype if needed --->
        WHERE company_name = <cfqueryparam value="#ARGUMENTS.customer_name#" cfsqltype="cf_sql_varchar">
    </cfquery>
    </cfoutput>
    <cfreturn addressDetail>
</cffunction>

The problem I'm having is that my output in my HTML form field looks like this: Column1Column2

How can I output that to have a space between each output?

Thanks!

Brian Fleishman
  • 1,237
  • 3
  • 21
  • 43

1 Answers1

1

Consider

 <cffunction name="getAddress" access="remote" returnType="string">

 ...
 <cfreturn SerializeJSON(addressDetail, "struct")>
James A Mohler
  • 11,060
  • 15
  • 46
  • 72
  • 1
    Or, add an argument to the function to specify the return type. CFCs come under the category of reusable code and there might be occasions where you call the function from CF code and would prefer to get back a query. – Dan Bracuk Aug 14 '20 at 02:47
  • Having just the query results would be best. I just want to output the returned data from the two columns. When it’s just one column I’m querying it’s simple to output, but with two columns the output shows as: [objsct Object] – Brian Fleishman Aug 14 '20 at 09:56
  • Found how to output the query results a little better, but need help with formatting the output. I updated my question. – Brian Fleishman Aug 14 '20 at 12:38