All,
 
I recently created a small CFC returning query results in JSON format.  The
querying works, the regular CF page is able to call the CFC as a WSDL page
properly passing params, and I am getting back JSON-like content.  However I
have been unable to parse the JSON content like an array within jQuery.  I
put the JSON variable inside an alert function in the CF page and I got a
JSON-like string.
 
I then replaced the web service URL in my CF page with the one from the
following page:
http://docs.jquery.com/Ajax/jQuery.getJSON#urldatacallback
When I reloaded the same CF page I got "[object Object]" and I was able to
parse the results from that web service.  So it seems like I'm missing
something in my CFC that turns my JSON content into an object.  I hope it's
something obvious...
 
My code is as follows:
 
==================================================
Component:
 
<cfcomponent output="no">
 
 <cffunction name="getDateStamp" returntype="string" output="no"
access="remote">
        <cfreturn DateFormat(Now())>
 </cffunction>
  
 <cffunction name="getEmpInfo" access="remote" returntype="string"
returnFormat="json" output="no">
     <cfargument name="searchparam" required="no" default="">
    
     <cfscript>
    strQuery = "SELECT empname, oprid , str(emplid) as emplid FROM
cae_alionOrgByUser where 1=1";
    
    // "structKeyExists" is needed to use REFind
    if ( (structKeyExists(arguments,"searchparam") eq "Yes") AND
(searchparam neq "") ) {
     if (REFind("[A-Za-z\.]+", searchparam) gt 0) {
      strQuery = strQuery & " and oprid like '%#searchparam#%'";
     }
     if (REFind("\d+", searchparam) gt 0) {
      strQuery = strQuery & " and emplid like '%#searchparam#%'";
     }
    }
    
    strQuery = strQuery & " ORDER BY empname";
    
   </cfscript>
        
        <cfquery name="getDis" datasource="idb4PeopleSoft">
         #preservesinglequotes(strQuery)#
        </cfquery>
        <cfset dis = serializeJSON(getDis)>
        
        <!--- 
        <cfoutput query="getDis">
        
        <cfset aEmpName = ListToArray(empname,",")>
        <cfset aEmpName0 = ListToArray(aEmpName[2]," ")>
    <cfset lname = aEmpName[1]>
        <cfset fname = aEmpName0[1]>
        <cfset minit = "">
    <cfif arraylen(aEmpName0) gt 1>
          <cfset minit = aEmpName0[2]>
        </cfif>
            
         <cfset strEmpInfo = strEmpInfo & strComma & "" & fname & " " &
minit & " " & lName & " (" & oprid & ":" & emplid & ")">
    <cfif cntEmpInfo eq 0>
             <cfset strComma = """,""">
            </cfif>
            <cfset cntEmpInfo = 1>
   --->
            
            
        <!--- </cfoutput> --->
        
        <!--- <cfset strEmpInfo = strEmpInfo & """]"> --->
        <!--- <cfreturn serializejson(getDis)> --->
        <cfreturn dis>
 </cffunction>
</cfcomponent>
 
==================================================
CF page: JavaScript
 
   var wsURL = '/ws/emp.cfc?wsdl';
   // var wsURL =
'http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any
&format=json&jsoncallback=?';
   $.getJSON(wsURL, {
    method: 'getEmpInfo',
    searchParam: '101'
    },
    function(jsondata) {
     alert(jsondata);
     alert(jsondata.DATA);
     // alert(jsondata.title);
     // $.each(jsondata.items, function(i,item){
     //  alert(item);
     // });
    }
   );
 
==================================================
 
tia,
 
 - Joe


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f

Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:317412
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to