2

我一直在尝试找到一种方法来做一些看起来很简单但似乎无法找到解决方案的方法。我有一篇用一些 HTML 制作的帖子,并希望动态更改其中的部分内容。我将 Coldfusion 9 用于服务器端、AJAX 和 jQuery UI 1.10.1 和 jQuery 1.9.1。

我想做的是在 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);

                    }
                });

我想用“Session.Variable1”替换“PersonsID”,用“Session.Variable2”替换“Persons Name”。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 回答