【发布时间】:2011-05-24 22:33:56
【问题描述】:
我正在使用 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()
【问题讨论】:
-
Firebug 告诉您有关请求的什么信息?
-
我对这一切有点陌生,我如何看待 firebug?
-
Firebug 显示 IIS 内部服务器错误 (http: 500)
-
好的,那么请检查您的错误日志 - CF 错误中记录了什么?
-
哦,伙计! returnformat=json 在 CF7 中不起作用。在 CF7 中,您可以返回 WDDX(默认值),或者如果您使用 returnTYpe=xml,则返回纯字符串。
标签: jquery ajax coldfusion cfc application.cfc