2014-07-18 40 views
2

我一直在努力解決這個錯誤,似乎無法找到解決方案。我正在使用FW/1 - Framework One 2.2,ACF 9,MS SQL 2008,jQyery 1.10.2。 我想通過AJAX發佈一個簡單的表單,我收到此錯誤消息。任何有識之士都非常感謝!錯誤:「參數傳遞...不是字符串類型。」

詳細信息:如果將組件名稱指定爲此參數的類型,則可能無法找到組件的定義文件或無法訪問該組件的定義文件。

消息:傳遞給setTaskLog函數的TASKLOG參數不是字符串類型。 enter image description here

<form id="taskActivityForm">  
    <input type="text" name="id" value=""> 
    <input type="text" id="taskID" name="taskID" value=""> 
    <div class="modal-body"> 
     <textarea name="taskLog" id="taskLog" class="input-block-level" rows="5"> </textarea> 
    </div> 
</form> 

jQuery的

enter image description here

$.ajax({ 
    type: "POST", 
    url: "/ccc/tasklog/save", 
    dataType: "json", 
    data: $("#taskActivityForm").serialize(), 
    success: function(returnData){ 
     console.log(returnData); 
    }, 
    error: function (jqXHR, textStatus, errorThrown) { 
     console.log(textStatus); 
     console.log(errorThrown); 
    } 
    }); 

型號TaskLog.cfc

<cfcomponent displayname="TaskLog" output="false"> 
<cfset variables.id = "" /> 
<cfset variables.taskID = "" /> 
<cfset variables.taskLog = "" /> 
<cfset variables.postedBy = "" /> 
<cfset variables.postedById = "" /> 

<cffunction name="init" access="public" output="false" returntype="TaskLog"> 
    <cfreturn this /> 
</cffunction> 

<cffunction name="setId" access="public" output="false"> 
    <cfargument name="id" type="string" required="true" /> 
    <cfset variables.id = arguments.id /> 
</cffunction> 
<cffunction name="getId" access="public" returntype="string" output="false"> 
    <cfreturn variables.id /> 
</cffunction> 

<cffunction name="setTaskID" access="public" output="false"> 
    <cfargument name="taskID" type="string" required="true" /> 
    <cfset variables.taskID = arguments.taskID /> 
</cffunction> 
<cffunction name="getTaskID" access="public" returntype="string" output="false"> 
    <cfreturn variables.taskID /> 
</cffunction> 

<cffunction name="setTaskLog" access="public" output="false"> 
    <cfargument name="taskLog" type="string" required="true" /> 
    <cfset variables.taskLog = arguments.taskLog /> 
</cffunction> 
<cffunction name="getTaskLog" access="public" returntype="string" output="false"> 
    <cfreturn variables.taskLog /> 
</cffunction> 

<cffunction name="setPostedBy" access="public" output="false"> 
    <cfargument name="postedBy" type="string" required="true" /> 
    <cfset variables.postedBy = arguments.postedBy /> 
</cffunction> 
<cffunction name="getPostedBy" access="public" returntype="string" output="false"> 
    <cfreturn variables.postedBy /> 
</cffunction> 

<cffunction name="setPostedById" access="public" output="false"> 
    <cfargument name="postedById" type="string" required="true" /> 
    <cfset variables.postedById = arguments.postedById /> 
</cffunction> 
<cffunction name="getPostedById" access="public" returntype="string" output="false"> 
    <cfreturn variables.postedById /> 
</cffunction> 
</cfcomponent> 

控制器TaskLog.cfc

<cfcomponent displayname="TaskLog" output="false"> 
<cfset variables.fw = "" /> 

<cffunction name="init" access="public" output="false" returntype="any"> 
    <cfargument name="fw"> 
    <cfset variables.fw = arguments.fw> 
    <cfreturn this> 
</cffunction> 

<cffunction name="setTaskLogService" access="public" output="false" returntype="void"> 
    <cfargument name="taskLogService" type="any" required="true" /> 
    <cfset variables.taskLogService = arguments.taskLogService /> 
</cffunction> 
<cffunction name="getTaskLogService" access="public" output="false" returntype="any"> 
    <cfreturn variables.taskLogService /> 
</cffunction> 

<cffunction name="save" access="public" output="false" returntype="void"> 
    <cfargument name="rc" type="struct" required="true"> 
    <cfset var taskLogService = getTaskLogService() /> 

    <cfset rc.tasklog = taskLogService.get(argumentCollection=rc) /> 
    <!--- update the tasklog object with the data entered ---> 
    <cfset variables.fw.populate(cfc=rc.tasklog, trim=true)> 
    <!--- call save function in services ---> 
    <cfset saveTaskLog= taskLogService.save(rc)> 
    <cfif saveTaskLog.success> 
     <cfset rc.id = saveTaskLog.id> 
    </cfif> 

    <cfset variables.fw.renderData("json", rc)> 
</cffunction> 

<cffunction name="list" access="public" output="false" returntype="void"> 
    <cfargument name="rc" type="struct" required="true"> 

    <cfset rc.tasks = gettaskLogService().list(rc=rc)> 
</cffunction> 

</cfcomponent> 

服務tasklog.cfc

我做了cfdump在get函數新的()調用之前。 「測試」對我來說似乎是一個字符串。 enter image description here

<cfcomponent displayname="TaskLogService" output="false"> 

<cfset variables.taskLogs = structNew()> 

<cffunction name="init" access="public" output="false" returntype="any"> 
    <cfreturn this> 
</cffunction> 

<cffunction name="new" access="public" output="false" returntype="any"> 
    <cfreturn createObject("component", "ccc.model.taskLog").init()> 
</cffunction> 

<cffunction name="get" access="public" output="false" returntype="any"> 
    <cfargument name="id" type="string" required="false" default=""> 
    <cfset var result = ""> 

    <cfif arguments.id neq ""> 
     <cfquery datasource="#application.dsn#" name="qTaskLogByID"> 
      select * from taskLogs where id =<cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.id#"> 
     </cfquery> 
    </cfif> 

    <cfif len(id) AND qTaskLogByID.RecordCount> 
     <cfset taskLog = new()> 
     <cfset taskLog.setId(qTaskLogByID.id)> 
     <cfset taskLog.settaskId(qTaskLogByID.taskId)> 
     <cfset taskLog.settaskLog(qTaskLogByID.taskLog)> 
     <cfset taskLog.setpostedBy(qTaskLogByID.postedBy)> 
     <cfset taskLog.setpostedById(qTaskLogByID.postedById)> 
     <cfset result = taskLog> 
    <cfelse> 
     <cfset result = new()> 
    </cfif> 

    <cfreturn result> 
</cffunction> 

<cffunction name="save" access="public" output="false" returntype="any" returnformat="JSON"> 
    <cfargument name="rc" type="any" required="true"> 
    <cfset var local = structNew()> 

     <cfif rc.id NEQ ""> 
      <cfquery datasource="#application.dsn#"> 
       update statement… 
      </cfquery> 
     <cfelse> 
      <cfquery datasource="#application.dsn#" name="qTaskLogInsert"> 
       insert into taskLogs (taskId,taskLog,postedBy,postedById) 
       values (
        <cfqueryparam cfsqltype="cf_sql_integer" value="#rc.task.getTaskId()#">, 
        <cfqueryparam cfsqltype="cf_sql_varchar" value="#rc.task.getTaskLog()#">, 
        <cfqueryparam cfsqltype="cf_sql_varchar" value="#rc.task.getPostedBy()#">, 
        <cfqueryparam cfsqltype="cf_sql_varchar" value="#rc.task.getPostedById()#"> 
        ) 

       select @@IDENTITY as newID 
      </cfquery> 
     </cfif> 
     <cfset local.response['id'] = qTaskLogInsert.newID> 
     <cfset local.response['success'] = true> 


<cfreturn local.response> 
</cffunction> 

</cfcomponent> 

預先感謝您爲您的見解!

+1

您的問題的標題是誤導性的,因爲它是錯誤「詳細信息」,而不是錯誤「消息」。這種情況下的細節與您的實際錯誤無關,並且是CF引擎可能發生的情況的假設。由於您沒有爲參數指定組件名稱,因此詳細信息不適用於您。 –

+0

我明白你的觀點,讓我看看我能否改變這一點。 – user752746

+0

我提交了一個標題編輯,但它告訴我必須通過同行評審。我不是一個S/O神,所以我沒有這些權力:) –

回答

3

您正在使用組件實例覆蓋rc.taskLog,該組件實例會清除從窗體提交的字符串。

<cfset rc.tasklog = taskLogService.get(argumentCollection=rc) /> 

爲您的組件實例選擇與您的表單域不同的變量名稱。

+0

嗨布拉德,感謝您的快速回復。我會做出改變,並讓你知道它的發展。再次感謝! – user752746

+0

就是這樣,不能相信我錯過了那個。再次感謝您的見解! – user752746

相關問題