0

フォルダーを循環し、そのフォルダー内のファイルを削除する CFC があります。これは、画像がアップロードされて保存された後の一種の「クリーンアップ」機能です。同じ CFC に、データベース内のテキストを更新する関数があります。ボット関数は、jQuery 投稿を通じて起動されます。テキスト関数は、jQuery 関数に確認を返しますが、問題ありません。

しかし、クリーンアップ機能は私のページにデータを返しません。クリーンアップ関数がページにデータを返して確認を実行するのを妨げる明らかなエラーがコーディングに見られる人はいますか?

ファイルがフォルダーから削除されているため、CFC が機能していることはわかっていますが、単に「有効な」応答が返されません。

jQuery は次のとおりです。

function rebinder(deleteImages){
    $('.editingFormField').attr('value', '');
    if ($('.edit').hasClass('selected')){
        $('.edit').removeClass('selected');
    }
    $('#imagePreview').attr('src', '');
    $('#et').dialog('close');
    $('#ei').dialog('close');
    if (deleteImages == 'yes'){
        $.post("cfc/engine.cfc?method=clearImages&returnformat=json", 
                    {},
                    function(ret) {
                        //Handle the result
                        alert(ret + "the Return");
                        if(ret == "true") {

                        } else {
                            alert("There was an error in the processing (files_no_del)");
                        }
                    });
        $.post("cfc/engine.cfc?method=clearThumbs&returnformat=json", 
                    {},
                    function(ret2) {
                        //Handle the result
                        if(ret2 == "true") {

                        } else {
                            alert("There was an error in the processing (thumbs_no_del)");
                        }
                    });
    }
    location.reload();
};

そしてCFC:

<cffunction name="clearImages" access="remote" output="false" returntype="boolean">
<cfset var deleteConfirm = "true">
<!--- Read Holding Directory --->
<cfdirectory
    action="list"
    directory="#destdir#"
    recurse="true"
    listinfo="name"
    name="qFile"
    />
  <!--- Loop through file query and delete files --->

<cfloop query="qFile">
<cffile action="delete" file="#destdir#/#qFile.name#">
</cfloop>
<cfreturn deleteConfirm>
</cffunction>
4

2 に答える 2

1

このコードはlocation.reload();、CFC から応答が返されたときに起動するコードのセクションに reload コマンドを移動すると、正常に機能しました。Nick Craver がこの投稿で問題を取り上げました: jQuery window reload does not allow to work post

Tony と Ken のコメントも問題の診断に役立ちました。投稿 URL を実行すると、AJAX マジックが計画どおりに実行されていることが確認されました。

動作する改訂されたコードは次のとおりです。

function rebinder(deleteImages){
    $('.editingFormField').attr('value', '');
    if ($('.edit').hasClass('selected')){
        $('.edit').removeClass('selected');
    }
    $('#et').dialog('close');
    $('#ei').dialog('close');
    $('#imagePreview').attr('src', '');
    if (deleteImages == 'yes'){
        $.post("cfc/engine.cfc?method=clearImages&returnformat=json", 
                    {},
                    function(ret) {
                        //Handle the result
                        if(ret == "true") {
                            location.reload();

                        } else {
                            alert("There was an error in the processing (files_no_del)");
                        }
                    });
    } else {
        location.reload();
    }
};

私が行った唯一の実際の変更は、CFC を少し統合することでした。2 つのフォルダーをクリーンアップするために 2 つのメソッドを実行する代わりに、両方のフォルダーを空にする 1 つの「クリーンアップ」メソッドに要約しました。

于 2010-08-05T19:17:56.803 に答える
0

$.getJSON() 関数を使用して CFC を呼び出すことができますか。呼び出したいメソッドに言及し、必要に応じてそのメソッドに引数を渡すことができます。

$.getJSON('Some.cfc', {method: 'fetchImapStartMessages', arg1: 'Hello',
    returnformat: 'json' },
  function(returndata) {
    //some code here that renders the data
  }
}); 

CFC メソッドで属性 returnformat = "JSON" access="remote" を設定していることを確認してください。CFC メソッドからデータが返される場合は、必ず serializeJSON(returndata) を使用してください。これは役に立ちますか?

于 2010-08-05T17:03:43.313 に答える