问题
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