我有一個使用.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