1

私はColdFusionMX7を使用して単純なフォームに取り組んでいます。cfselectで選択されたものに基づいて入力したいテキスト入力のペアがあります。私のCFCへのAjax呼び出しは、404エラーを返します。ブラウザからCFCにアクセスしても、そのようなエラーは発生しません。これは、CFC用のカスタムJavaプロキシを作成するBenNadelの例を使用して作成しました。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()
4

2 に答える 2

1

CFCメソッドがaccess="remote"としてマークされていることを確認してください。

http://servername/path/to/cfc/nameofcfc.cfc ? method=methodName&arg1=arg1value(値を自分の値に置き換える)を実行すると、機能しますか?それから「ajax」を取り出してください

于 2010-12-13T22:00:37.023 に答える
1

そして、Firebug(またはCharles、Fiddler、または他のプロキシが教えてくれるかもしれない)についてのRayの質問に加えて、それが本当に404エラーである場合は確かに役立つはずですが、そうでない場合は他の考えがあります。

まず、ブラウザからアクセスできると言うとき、それはhttp://yourserver/yourcfc.cfc?method=methodnameという意味ですか?または、他の何か?また、returnformat = jsonを追加してajaxライブラリを表示しているので、それをURLにも追加してテストしますか?

次に、application.cfcまたはcfmを使用していないと言うとき、それはそのディレクトリにあるかどうかだけでなく、親、祖父母などにもあることに気づきますか?あなたはそれらの1つによって影響を受ける可能性があります。これを回避する最も簡単な方法は(テスト目的で)、呼び出しているページのディレクトリに空白のものをドロップすることです。

第三に、application.logファイル([cf] \ logs内、またはCF Admin経由)を見ると、エラーが発生していることがわかりますか?Ajaxクライアントは通常それを隠します。確かに、あなたは404を取得することに言及しています。それが見つからないCFCであると確信していますか?何がそれを報告していますか?

そして、CFCはこのHTML / javascriptを提供したCFページと同じディレクトリにありますか?ファイルに名前を付けるだけなので、そこを探しているように見えます。ブラウザのサンプルURLでそれをテストしましたか?

于 2010-12-13T22:11:46.287 に答える