我有一个使用.post提交给我的cfc的页面。我知道该函数可以正常工作,因为数据库正在更新,但是正在触发的警报是'else'语句中的警告。为什么我的jQuery不认识到我的CFC的回报?
你们中的任何一个人都能看出为什么我的回报没有发出正确的警报吗?我没有正确捕获回报吗?
我的一些变量是硬编码为测试目的...
jQuery的:
$(document).ready(function() {
var theID = $('#window_one h1').attr('name').split("-")[1];
var gateway = ("001");
//Populate the form
$('#theText').attr('value', $('#window_one h1').html());
$('#texteditform').submit(function(e){
//stop the form submission
e.preventDefault()
var newText = $('#theText').val();
//CFC
$.post("cfc/engine.cfc?method=updateText&returnformat=json",
{text:newText, field:theID, gateway_id:gateway},
function(res) {
//Handle the result
if(res == "true") {
alert("worked fine");
} else {
alert("Didn't Work");
}
});
});
});
</script>
的CFC
<cffunction name="updateText" access="remote" output="no" returntype="boolean">
<cfargument name="field" type="string" required="yes">
<cfargument name="text" type="string" required="yes">
<cfargument name="gateway_id" type="string" required="yes">
<cfquery datasource="#application.datasource#" username="#application.username#" password="#application.password#">
UPDATE gateway
SET #arguments.field# = <cfqueryparam value="#arguments.text#" cfsqltype="cf_sql_varchar">
WHERE gateway_id = #arguments.gateway_id#
</cfquery>
<cfreturn true>
</cffunction>
什么是确切的响应?检查这在萤火虫或提琴手。 我不知道cfc,但你已经将你的方法标记为远程,所以这意味着服务器端脚本返回包装在js函数(jsonp)中的json? – redsquare 2010-07-13 19:04:31
Firebug说回答是'真' – Ofeargall 2010-07-13 19:08:20
好的,这是修复,我认为...如果我写这样的条件语句如果(response.trim()==“true”) 它工作正常。那里的任何ColdFusion专家都能告诉我为什么我的回报有额外10个硬回报吗? – Ofeargall 2010-07-13 19:19:10