I have the following code that doesn't work. But when I browse the CFC is works perfectly. Thoughts?
source: "/contentfiles/ajaxlookup.cfc?method=getInstitutions&returnformat=jso n"
category: <input id="searchPhrase" />
Btw, my answer here http://forums.adobe.com/thread/1319717?tstart=0 refers to a script that uses Ajax already, and the data is JSON encoded too.
It's on my DEV server and it may not work on my prod server because the server admin hasn't turned on remote access yet.
Here is my code:
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/redmond/jquery- ui.css">
source: "<cfoutput>#request.serverURL#</cfoutput>/contentfiles/ajaxlookup.cfc ?method=getInstitutions&returnformat=json"
category: <input id="category" name="category" />
And here is my CFC:
<cffunction access="remote" name="getInstitutions" returntype="any">
<cfargument name="searchPhrase" type="any" required="true" default="">
<!--- Define variables --->
<cfset var result=ArrayNew(1)>
<!--- Do search --->
<cfquery datasource="#request.dsn#" name="data">
WHERE LOWER(strInstitutionName) LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="%#LCASE(arguments.searchPhrase)#%" />
AND bitselectionlist = 1
AND bitActive = 1
AND IntInstitutionCategoryID IN (1,2,3,6,7,8,9)
AND bitRemoteLogin <> 1
ORDER BY strInstitutionName
<!--- Build result array --->
<cfset ArrayAppend(result, strInstitutionName)>
<!--- And return it --->
jQuery is nothing to do with ColdFusion. You are just using ColdFusion to serve out data from a database query. You will have to find a way to get your code online so we can see it, since there are many dozens of reasons as to why code does not work the way it should.
I think my data is in the wrong format. Here is my response:
//"\/\/[\"Miami Area Geriatric Education Center\",\"Miami Children's Hospital\",\"Miami Research Associates\",\"Miami University (Oxford, Ohio)\",\"Miami Valley Hospital\",\"Miami, FL-546\",\"University of Miami\\\/Jackson Health System\"]"
The ongoing thread here http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:64866 is really saying the same thing you and I are, namely that the data is not in the correct format (as you know). That thread made mention to this article: http://www.petefreitag.com/item/720.cfm. The leading "//" on the front of that data shows that secure JSON is enabled. This "//" prefix needs to be removed from the data. Can you put this in your code to turn secure JSON off and then see what response you get?
<cfset this.secureJSON = false>
Ok I got it to work!!
&returnformat=plain to my method call
secureJSON = "yes" to my function
I also added this to my component: <cfset this.secureJSON = true> <cfset this.secureJSONPrefix = "//">
Of course I was still getting // prefix. I googled secureJSON prefix and found this article: http://www.raymondcamden.com/index.cfm/2011/11/8/Handling-JSON-with-pr efixes-in-jQuery-and-jQueryUI
I added the data filter and it worked!