【问题标题】:return variable undefined in jQuery $.post sent by a cfc返回由 cfc 发送的 jQuery $.post 中未定义的变量
【发布时间】:2012-04-12 21:35:24
【问题描述】:

我正在使用$.post() 向我的cfc 发送一个json,它会更新一些记录。我没有将 json 返回到调用页面,我只是返回我在 cfc 中设置的变量的内容。根据该变量的值,更新成功/失败。我似乎无法了解变量的内容。我刚开始使用 jQuery,所以我认为我做得对,但显然不是。

jQuery:

$("#edit_button").click(function(){
    if(theArray.length > 0){
        theJson = JSON.stingify(theArray);
        $.post("cfcs/fund_profile.cfc",{
            method:"updateProfile",
            data:theJson,
            dataType:"text"
            success:function(response){alert(response);}
        });
   }
});

我不会发布整个 cfc,只发布重要部分。

我只是返回一个字符串。

<cffunction name="updateProfile" ...>
    ...

    <cfif message neq ''>
        <cfreturn message>
    <cfelse>
        <cfset message = "success">         
    </cfif>
    <cfreturn message>
</cffunction>

【问题讨论】:

  • 仅供参考,您不是将 JSON 发送到 cfc,而是发送一个字符串。

标签: jquery coldfusion cfc


【解决方案1】:

您错误地使用了$.post。这看起来像是$.ajax$.post 的混合体。您的调用应如下所示:

$.post("cfcs/fund_profile.cfc",{ method: "updateProfile", data: theJson}, 
    function(response) {
       alert(response);
    }, 
"text");

文档:http://api.jquery.com/jQuery.post/

【讨论】:

  • @karmin79 成功了。我一直在查看 jquery api 参考,我觉得我做错了什么,但我无法破译是什么。谢谢。
猜你喜欢
  • 1970-01-01
  • 2011-10-26
  • 1970-01-01
  • 2020-08-21
  • 2012-08-02
  • 1970-01-01
  • 1970-01-01
  • 2016-05-03
  • 2011-11-06
相关资源
最近更新 更多