我正在使用 ColdFusion MX7 制作一个简单的表格。我有一对文本输入,我想根据在 cfselect 中选择的内容进行填充。对我的 CFC 的任何 Ajax 调用都会返回 404 错误。如果我从浏览器访问 CFC,则不会出现此类错误。我使用 Ben Nadel 为 cfc 制作自定义 java 代理的示例制作了这个。cfc 与该脚本所在的 cfm 页面位于同一文件夹中。以下是相关代码:
function RemoteCFC(){
this.name = " ";
return( this );
}
// This handles the remote calls to the CFCs.
RemoteCFC.prototype.MakeRemoteCall = function(strMethod, objData, fnSuccess, fnError){
// Create a data struct and extend it with the method
// name and the data to be passed.
var objRemoteData = {};
// Extend the remote data set.
$.extend(objRemoteData, objData, {method: strMethod, returnFormat: "json"});
// Make the AJAX call to the remote method.
$.ajax({type: "get", url: (this.Name + ".cfc"), data: objRemoteData, dataType: "json",
success: fnSuccess, error: fnError});
// Return this for method chaining.
return( this );
}
// Create a new core remote object. We will need this
// to create the prototype chain such that the other
// proxy classes can extend this.
objRemoteCFC = new RemoteCFC();
// Create a Javascript proxy for this given CFC.
function RecallService(){
this.Name = "RecallCountFunctions";
}
// Extend the core CFC Proxy functionality.
RecallService.prototype = objRemoteCFC;
RecallService.prototype.getInspected = function( objData, fnSuccess, fnError ){
this.MakeRemoteCall( "getInspected", objData, fnSuccess, fnError );
}
//Define another remote method wrapper.
RecallService.prototype.getHeld = function( objData, fnSuccess, fnError ){
this.MakeRemoteCall( "getHeld", objData, fnSuccess, fnError );
}
$(
function(){
var myRecallService = new RecallService();
$( "select[ name = 'CountChosen' ]" ).change( function(){
var selectedCount = $( "select[ name = 'CountChosen' ]" );
var inspected = $("input[name='numInspected']");
var held = $("input[name='numHeld']");
if (selectedCount.val() != "0"){
EnableForm();
myRecallService.getInspected({store: "#cgi.AUTH_USER#", id: selectedCount}, function
( objResponse ){SetValue("inspected", objResoponse );}, function( objResponse ){
alert( objResponse.responseText );});
myRecallService.getHeld({store: "#cgi.AUTH_USER#", id: selectedCount}, function
( objResponse ){SetValue("held", objResponse);}, function( objResponse ){
alert( objResponse.responseText);});
}
});
}
很抱歉这篇长文,我不想遗漏任何可能有帮助的东西。我也没有使用我听说可能会导致问题的 Application.cfc 或 onRequest 方法。
如果您需要查看我的 cfc,请告诉我,我也可以发布它。
修复是:
Change:
id: selectedCount
To:
id: selectedCount.val()