FW1初心者です。私は基本を持っていますが、それを機能させようとすると、他のライブラリが苦痛になります。何がうまくいかないのかを理解するのは難しいです。
AJAX と jQuery(submitForm.js) を使用して、newServer.cfm のフォーム データを main.cfc のコントローラー関数に投稿したいと考えています。コントローラー関数はデータをサービス (submit.cfc) に送信し、サービス (submit.cfc) はデータを DAO (submit.cfc) に送信してデータベースに挿入します。次に、成功したかどうかのステータスを返します。
フォルダ構造
submitForm.js
$(document).ready(function() {
$("#submitForm").submit(function(){
dataString = $("#submitForm").serialize();
$.ajax({
type: "POST",
url: "index.cfm?action=main.submit",
dataType: "json",
data: dataString,
success: function(response) {
$("#result").html(response);
},
error: function(xhr, status, e) {
$("#result").html(status);
}
});
});
});
main.cfc (コントローラー)
<cfcomponent accessors="true" output="false">
<cfproperty name="submitService">
<cfscript>
function init( fw ) {
variables.fw = fw;
return this;
}
public function submit(rc){
json = deserializeJson(rc);
rc.status = submitService.submitForm(json);
}
</cfscript>
</cfcomponent>
submit.cfc (サービス)
<cfcomponent accessors="true">
<cfproperty name="submitDAO">
<cffunction name="submitForm" returnType="boolean" access="public" output="false" hint="I return a list of blog entries">
<cfargument name="json" type="struct" required="true" hint="" displayname="rc" />
<cfset status = "">
<cfset status = submitDAO.submitForm(json)>
<cfreturn status>
</cffunction>
</cfcomponent>
確認のために、DAO からブール値を返しています。
submit.cfc(DAO)
<cfcomponent accessors="true">
<cffunction name="init" hint="I return an instance of myself">
<cfreturn this>
</cffunction>
<cffunction name="submitForm" returntype="boolean" hint="I return a list of blog entries">
<cfargument name="json" type="struct" required="true" hint="" displayname="rc" />
<cfset var status = true>
<cfreturn status>
</cffunction>
</cfcomponent>
フォームデータを送信していますが、その後応答がありません。Firebug は、jQuery 行 8630 でエラーを示しています。
xhr.send( options.hasContent && options.data || null );
ajax 関数の URL を「controllers/main.cfc?method=submit」に変更しようとしましたが、それでもうまくいきません。