返回变量在由cfc发送的jQuery $ .post中未定义 [英] return variable undefined in jQuery $.post sent by a cfc
问题描述
我使用 $。post()
发送一个json到我的cfc,更新一些记录。我不返回一个json回调用页面,我只是返回一个变量的内容,我在cfc中设置。基于该变量的值,更新/未成功。我似乎得不到变量的内容。我刚开始使用jQuery,所以我认为我是做对,但显然不是。
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.
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,只是重要的部分。
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>
推荐答案
您正在使用 $。 post
不正确。这看起来像一个杂乱的 $。ajax
和 $。post
。您的来电应类似于以下内容:
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");
文件: http://api.jquery.com/jQuery.post/
这篇关于返回变量在由cfc发送的jQuery $ .post中未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!