我一直在尝试找到一种方法来完成一些看似非常简单的事情,但似乎找不到解决方案。我有一篇文章是用一些 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);
}
});
我想将“PersonsID”替换为“Session.Variable1”,将“Persons Name”替换为“Session.Variable2”。 CFC 将是 CF 的标准协议(protocol)。该组件如下所示。
<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>
任何建议都会很棒!
最佳答案
下面的代码可以工作,但如果他们查看源代码,它确实会暴露该人的 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);
}
});
关于jquery-ui - 如何在 cfc 中用 Coldfusion 替换 AJAX 帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15073837/