使用 AJAX 调用 ColdFusion 函数 [英] Invoke ColdFusion function using AJAX

查看:18
本文介绍了使用 AJAX 调用 ColdFusion 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户单击链接时,我需要调用 ColdFusion 函数(存在于 .cfm 文件中).我想用jQuery来做.我有一个 jQuery 片段,看起来像-

I need to invoke a ColdFusion function(present in a .cfm file) when the user clicks on a link. And I would like to do it using jQuery. I have a jQuery snippet which looks like-

<script type="text/javascript">
$(document).ready(function(){
       $("td.ViewLink a").click(function(event){
         event.preventDefault();

)}

我对 jQuery 和 AJAX 都很陌生,所以在这里我可能听起来很幼稚.我应该使用 AJAX 来调用 ColdFusion 函数吗?类似于请求在服务器上执行特定功能.

I am new to both jQuery and AJAX, so I might sound naive here. Should I use AJAX to invoke the ColdFusion function? Something like requesting to execute a specific function on the server.

感谢您提供这方面的任何帮助.

Any help in this regard is appreciated.

干杯.

推荐答案

如果您的 cfm 中有多个函数(即使您没有),请将它们放在 cfc 中.然后你可以使用下面的 url 模式来调用特定的方法.

If you have multiple functions in your cfm(even if you don't), put them in a cfc. Then you can use the following url pattern to invoke a specific method.

cfc 命名为 myEntityWS.cfc

cfc named myEntityWS.cfc

<cfcomponent>
  <cffunction name="updateDescription" access="remote" returntype="string">
    <cfargument name="value" type="string" required="yes">
    <cftry>
      your code here
    <cfcatch>
      <cfoutput>
        #cfcatch.Detail#<br />
        #cfcatch.Message#<br />
        #cfcatch.tagcontext[1].line#:#cfcatch.tagcontext[1].template#
      </cfoutput>
    </cfcatch>
    </cftry>
  </cffunction>
</cfcomponent>

Javascript

$.get('myEntityWS.cfc?method=updateDescription&value=someValue');

这篇关于使用 AJAX 调用 ColdFusion 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆