return variable undefined in jQuery $.post sent by a cfc

家住魔仙堡 提交于 2019-12-13 01:20:44

问题


I am using $.post() to send a json to my cfc, which updates some records. I am not returning a json back to the calling page, I am just returning the contents of a variable that I am setting in the cfc. Based on the value of that variable, the update was/was not successful. I cannot seem to get at the contents of the variable. I just started using jQuery, so I think I'm doing it right, but apparently not.

the 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);}
        });
   }
});

I'm not going to post the whole cfc, just the important part.

I am just returning a string.

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

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

回答1:


You are using $.post incorrectly. That looks like a mish-mash of $.ajax and $.post. Your call should resemble this:

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

Docs: http://api.jquery.com/jQuery.post/



来源:https://stackoverflow.com/questions/10124561/return-variable-undefined-in-jquery-post-sent-by-a-cfc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!