我正在尝试将表单发布到远程服务器。目前的总体思路是 HTML 将在本地运行并通过 AJAX 发布到远程服务器。
因此有一个表单、JS 和它要发布到的 CFC。
下面是JS
$(document).ready(function () {
$("#submit").click(function(){
var setName = $("input[name='setName']").val();
var setNumber = $("input[name='setNumber']").val();
var setTheme = $("input[name='setTheme']").val();
var retailPrice = $("input[name='retailPrice']").val();
var purchaseStore = $("input[name='purchaseStore']").val();
var purchaseDate = $("input[name='purchaseDate']").val();
var purchasePrice = $("input[name='purchasePrice']").val();
var condition = $("input[name='condition']").val();
var sellPrice = $("input[name='sellPrice']").val();
var sellStore = $("input[name='sellStore']").val();
var selldate = $("input[name='selldate']").val();
$.ajax({
type: 'get',
url: 'http://www.chesteraustin.us/cfc/entry.cfc?ReturnFormat=json',
data: {
method: 'setEntry',
Set_Name: setName, //CFARGUMENT: JS_VARIABLE
Set_Number: setNumber,
Set_Theme: setTheme,
Retail_Price: retailPrice,
Purchase_From: purchaseStore,
Purchase_Price: purchasePrice,
Purchase_Date: purchaseDate,
Status: condition,
Sell_Date: sellPrice,
Sell_from: sellStore,
Sell_date: selldate
},
contentType: 'json',
dataType: 'json',
success: function(response) {
console.log("you da man");
}
});
});
});
下面是它被发布到的 CFC(为简洁起见,我删除了其中的大部分内容):
<cfcomponent>
<cfheader name="Access-Control-Allow-Origin" value="*" />
<cfheader name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE" />
<cfheader name="Access-Control-Allow-Headers" value="Content-Type" />
<cffunction name="setEntry" access="remote">
<cfreturn 1>
</cffunction>
</cfcomponent>
编辑:清理了 CFC,删除了无关的评论。
做研究,我发现了这一点CFHEADER
本来应该放在最上面,以允许跨源,但是,Chrome 仍然提供了一个No 'Access-Control-Allow-Origin' header is present on the requested resource.
error.
一些背景知识:我在共享主机上。我在 CFC 所在的文件夹中有一个空白的 Application.CFC。