cfc发送的jQuery$.post中未定义返回变量
我正在使用cfc发送的jQuery$.post中未定义返回变量,jquery,coldfusion,cfc,Jquery,Coldfusion,Cfc,我正在使用$.post()向我的cfc发送一个json,它会更新一些记录。我没有将json返回到调用页面,我只是返回我在cfc中设置的变量的内容。根据该变量的值,更新未成功。我似乎无法理解变量的内容。我刚开始使用jQuery,所以我认为我做得不错,但显然不行 jQuery: $("#edit_button").click(function(){ if(theArray.length > 0){ theJson = JSON.stingify(theArray);
$.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>
...
您正在使用$。post
不正确。这看起来像是$.ajax
和$.post
的混合体。您的呼叫应类似于此:
$.post("cfcs/fund_profile.cfc",{ method: "updateProfile", data: theJson},
function(response) {
alert(response);
},
"text");
文档:FYI您不是在向cfc发送JSON,而是在发送一个字符串。@karmin79成功了。我一直在寻找jQueryAPI引用,我觉得我做错了什么,但我无法解释什么。谢谢