2010-07-13 58 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

相关问题