cfcを呼び出して、データのjson文字列を取得できるため、cfcは機能していますが、jquery ajax呼び出しで、「SyntaxError:JSON.parse:予期しないデータの終わり」というエラーが発生します。
ajax呼び出し:
$.ajax({
type: "get",
url: "/surveymanagement/admin/client.cfc",
dataType: "json",
data: {
method: "GetClientsByName",
name: "im"
},
success: function(data){
$("#here").html(data);
},
error: function(a,b,c){
$("#here").html(a.responseText + c);
}
});
別のcfmページでコンポーネントを呼び出すと、cfcは次の文字列を返します[{"client_id":58,"client_name":"Aimbridge"},{"client_id":104,"client_name":"IMF"}]
。
私の問題は何でしょうか?
また、ブラウザで直接cfcにアクセスしてもhttp://domain.com/filepath/client.cfc?method=GetClientsByName&name=im
エラーは発生しませんが、画面は白いだけです。直接行ったときに何が見えるのかわかりません。
ここにすべての情報のためにclient.cfcがあります:
<cfcomponent>
<cfsetting showdebugoutput="no">
<cffunction name="GetClientsByName"
access="remote"
returntype="string"
hint="get clients from search term">
<cfargument name="name" type="string" required="yes">
<cfset var util = createObject("component", "/surveymanagement/JSONUtil")>
<cfset var results = arrayNew(1)>
<cfset var elem = "">
<cfquery name="GetClientsByName" datasource="#application.dsn#">
SELECT client_id, client_name
FROM Clients
WHERE client_name LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="%#arguments.name#%">
</cfquery>
<cfloop query="GetClientsByName">
<cfset elem = structNew()>
<cfset elem["client_id"] = GetClientsByName.client_id>
<cfset elem["client_name"] = GetClientsByName.client_name>
<cfset arrayAppend(results, elem)>
</cfloop>
<cfcontent type="application/json" reset="true">
<cfreturn util.serializeJSON(results)>
</cffunction>
</cfcomponent>
注:coldfusion7を使用しているため、使用できませんreturnformat='json'
application.cfcここで問題が発生した可能性があります。
<cfcomponent
displayname="Application"
output="true"
hint="Handle the Application">
<cfset THIS.Name = "SurveyManagement" />
<cfset THIS.ApplicationTimeout = CreateTimeSpan(0,1,0,0) />
<cfset THIS.SessionManagement = true />
<cfset THIS.SetClientCookies = false />
<cffunction
name="OnApplicationStart"
access="public"
returntype="boolean"
output="false"
hint="Fires when the application is first created.">
<cfreturn true />
</cffunction>
<cffunction
name="OnSessionStart"
access="public"
returntype="void"
output="false"
hint="Fires when the session is first created.">
<cfreturn />
</cffunction>
<cffunction
name="OnRequestStart"
access="public"
returntype="boolean"
output="false"
hint="Fires at first part of page processing.">
<cfargument
name="TargetPage"
type="string"
required="true"
/>
<cfparam name="variables.this_query_string" default="">
<cfif cgi.QUERY_STRING neq "">
<cfset variables.this_query_string="?#cgi.QUERY_STRING#">
</cfif>
<cfparam name="server.ThisServer" default="www4.mydomain.com">
<cfif cgi.SERVER_PORT neq "443" or cgi.HTTP_HOST eq "www.mydomain.com">
<cflocation url="https://#server.ThisServer##cgi.PATH_INFO##variables.this_query_string#" addtoken="no">
</cfif>
<cfparam name="form.fieldnames" default="">
<cfloop list="#form.fieldnames#" index="i">
<cfif Evaluate(i) neq "">
<cfset form_value_temp=Evaluate(i)>
<cfset form_value_temp=replace(form_value_temp,"<", "<", "all")>
<cfset form_value_temp=replace(form_value_temp,">", ">", "all")>
<cfset "form.#i#"=form_value_temp>
</cfif>
</cfloop>
<cfreturn true />
</cffunction>
<cffunction
name="OnRequest"
access="public"
returntype="void"
output="true"
hint="Fires after pre page processing is complete.">
<cfargument
name="TargetPage"
type="string"
required="true"
/>
<cfset application.dsn="SurveyManagement">
<cfset application.title="Survey Management Site">
<cfset application.directory="surveymanagement">
<cfset application.cfc_data="surveymanagement">
<cfinclude template="#ARGUMENTS.TargetPage#" />
<cfreturn />
</cffunction>
<cffunction
name="OnRequestEnd"
access="public"
returntype="void"
output="true"
hint="Fires after the page processing is complete.">
<cfreturn />
</cffunction>
<cffunction
name="OnSessionEnd"
access="public"
returntype="void"
output="false"
hint="Fires when the session is terminated.">
<cfargument
name="SessionScope"
type="struct"
required="true"
/>
<cfargument
name="ApplicationScope"
type="struct"
required="false"
default="#StructNew()#"
/>
<cfreturn />
</cffunction>
<cffunction
name="OnApplicationEnd"
access="public"
returntype="void"
output="false"
hint="Fires when the application is terminated.">
<cfargument
name="ApplicationScope"
type="struct"
required="false"
default="#StructNew()#"
/>
<cfreturn />
</cffunction>
<cffunction
name="OnError"
access="public"
returntype="void"
output="true"
hint="Fires when an exception occures that is not caught by a try/catch.">
<cfargument name="Except" required=true/>
<p>AN UNEXPECTED ERROR HAS OCCURRED</p>
<p>Please consult your suggested technical support contact for assistance.</p>
<cfif findnocase("ip address here",cgi.REMOTE_ADDR) or findnocase("ip address here",cgi.REMOTE_ADDR)>
<cfdump var="#Except.RootCause#">
</cfif>
<cfreturn />
</cffunction>