2

私はかなり単純に見える何かを行う方法を見つけようとしていますが、解決策を見つけることができないようです。HTML を使用して作成された投稿があり、その一部を動的に変更したいと考えています。サーバー側、AJAX、および jQuery UI 1.10.1 & jQuery 1.9.1 に Coldfusion 9 を使用しています。

私がやりたいことは、AJAX に投稿し、cfc 内のデータ サーバー側を置き換えることです。クライアント側にあるコードは次のとおりです。

var ipost = '<li> <h2><a href="PersonsID" target="_blank">Persons Name</a></h2> </li>';
var message_a = $('#message_a').attr('value');

                $.ajax({
                    type: "POST",
                    url: "cfc/cfc_Forum.cfc?method=func_AddNew&returnformat=json",
                    data: { message:"message_a=" + wall_post },
                    success: function () {
                        $('ul#posts').prepend(ipost);

                    }
                });

「PersonsID」を「Session.Variable1」に、「Persons Name」を「Session.Variable2」に置き換えたいと思います。cfc は CF の標準プロトコルです。コンポーネントは次のようになります。

<cfcomponent>

    <cffunction name="func_AddNew" access="remote" returntype="struct">
    <cfargument name="message" type="string" required="true" />
        <--- ********** replace "Persons ID" and "Persons Name" ************** --->

        <!--- ********* INSERT INTO DATA BASE ************ --->

        <cfreturn return />
    </cffunction>   

</cfcomponent>

どんな推奨事項も素晴らしいでしょう!

4

1 に答える 1

1

以下のコードは機能しますが、ソース コードを見るとその人物の personID が公開されるため、これを行うには少しリスクがあります。他にできることは、cftolken を渡し、cfc で正しい変数を見つけようとすることです。これにはもう少し手間がかかります。

 $.ajax({
    type: "POST",
    url: "cfc/cfc_Forum.cfc?method=func_AddNew&returnformat=json",
    data: { message:"message_a=" + wall_post
          , personID: <cfoutput>#Session.Variable1#</cfoutput>
          , personName: <cfoutput>#Session.Variable2#</cfoutput>
            },
    success: function () {
         $('ul#posts').prepend(ipost);
                        }
                });
于 2013-02-25T21:24:47.300 に答える