2010-07-13 23 views
0

我有一個使用.post提交給我的cfc的頁面。我知道該函數可以正常工作,因爲數據庫正在更新,但是正在觸發的警報是'else'語句中的警告。爲什麼我的jQuery不認識到我的CFC的回報?

你們中的任何一個人都能看出爲什麼我的回報沒有發出正確的警報嗎?我沒有正確捕獲回報嗎?

我的一些變量是硬編碼爲測試目的...

jQuery的:

$(document).ready(function() { 
    var theID = $('#window_one h1').attr('name').split("-")[1]; 
    var gateway = ("001"); 
//Populate the form 
    $('#theText').attr('value', $('#window_one h1').html()); 
    $('#texteditform').submit(function(e){ 
     //stop the form submission 
     e.preventDefault()        
     var newText = $('#theText').val(); 
     //CFC 
     $.post("cfc/engine.cfc?method=updateText&returnformat=json", 
      {text:newText, field:theID, gateway_id:gateway}, 
      function(res) { 
       //Handle the result 
       if(res == "true") { 
        alert("worked fine"); 
       } else { 
        alert("Didn't Work"); 
       } 
      }); 
    });       
}); 

</script> 

的CFC

<cffunction name="updateText" access="remote" output="no" returntype="boolean"> 


    <cfargument name="field" type="string" required="yes"> 
    <cfargument name="text" type="string" required="yes"> 
    <cfargument name="gateway_id" type="string" required="yes"> 
<cfquery datasource="#application.datasource#" username="#application.username#" password="#application.password#"> 
    UPDATE gateway 
    SET #arguments.field# = <cfqueryparam value="#arguments.text#" cfsqltype="cf_sql_varchar"> 
    WHERE gateway_id = #arguments.gateway_id# 
    </cfquery> 
    <cfreturn true> 
</cffunction> 
+0

什麼是確切的響應?檢查這在螢火蟲或提琴手。 我不知道cfc,但你已經將你的方法標記爲遠程,所以這意味着服務器端腳本返回包裝在js函數(jsonp)中的json? – redsquare 2010-07-13 19:04:31

+0

Firebug說回答是'真' – Ofeargall 2010-07-13 19:08:20

+0

好的,這是修復,我認爲...如果我寫這樣的條件語句如果(response.trim()==「true」) 它工作正常。那裏的任何ColdFusion專家都能告訴我爲什麼我的回報有額外10個硬回報嗎? – Ofeargall 2010-07-13 19:19:10

回答

4

你的,因爲這樣多餘的空格是CF生成其輸出。你需要確保cfc本身被設置爲output =「false」...可能需要進一步的擺動,但這應該讓你開始。

這是一個比較煩人的功能之一,CF

+0

這個伎倆!在我的cfc中刪除了我所有的空白。所以現在的問題是,還有什麼會讓我不知道的東西呢......謝謝! – Ofeargall 2010-07-13 19:48:28

+0

可能沒什麼。你不想在組件級別輸出=「false」',而且它確實應該默認爲false。 – 2010-07-13 22:33:48

+0

我在ColdFusionJedi上發佈了Raymond Camden的這個問題,他幾乎說了同樣的話。在CF8中,他總是將CFC的輸出設置爲false。他確實提到這不是CF9的問題。 – Ofeargall 2010-07-15 17:44:36

相關問題