AJAX ColdFusionのテストを行っていますが、AJAXを使用してColdFusionサーバーにデータを送信する際に問題が発生しました。ColdFusion AJAX:引数で要素が定義されていません
<form method="post">
<p>
<input type="text" id="user_name" name="name" placeholder="name" value="test" />
<input type="text" id="user_email" name="email" placeholder="email" value="abc" />
</p>
<input type="button" value="Find Out" class="ajax_form"/>
</form>
<p id="insert"></p>
JS:
$(document).ready(function(){
$(".ajax_form").click(function(){
var that = $(this).parent(),
url = "ajax.cfc",
type = that.attr('method'),
test = {};
that.find('[name]').each(function(index, value){
var that = $(this),
name = that.attr('name'),
value = that.val();
test[name] = value;
});
console.log(test.name);
$.ajax({
url: url,
type: type,
data: {
method: "testCheck",
name: test.name,
email: test.email,
array: test
},
success: function (responce){
document.getElementById('insert').innerHTML = responce;
},
error: function (xhr, textStatus, errorThrown){
alert(errorThrown);
}
});
});
});
ajax.cfmは本当に簡単で、このようになります は、ここで私が持っているHTMLコードです。 (:「500(要素の配列を引数を未定義である)」私が取得エラー)がまたは私はそれを設定すると、デフォルト値を取得します
<cfcomponent output="false">
<cffunction name="testCheck" access="remote" returnformat="plain" returnType="string" output="false">
<cfargument name="name" type="string" required="false" />
<cfargument name="email" type="string" required="false" />
<cfargument name="array" required="false" />
<cfset var string = " " />
<cfif (arguments.name) eq "test">
<cfset string = arguments.array/>
<cfelse>
<cfset string = "incorrect" />
</cfif>
<cfreturn string />
</cffunction>
</cfcomponent>
問題は、CF引数が定義されていないということです。私はこれが私が送信しているオブジェクトのデータ型に関するものだと推測していますが、私は解決策を考え出すことはできません。この場合、cfargumentとしてこのタイプのデータを使用することは可能ですか?
JSオブジェクトをCFに直接渡すことはできないと思います。最初にシリアル化して文字列として渡す必要があります。次に、CF関数で逆シリアル化します。 – Alex