使用 JQuery Ajax 调用 .cfm 和 .cfc 的区别?

Difference between calling .cfm and .cfc with JQuery Ajax?

我正在开发新系统,几乎没有什么与我以前看到的不同。基本上有一个 JQuery ajax 调用 "POST" 类型和 url 指向 .cfm 页面。 .cfm 页面将 return html table。

在与首席开发人员交谈后,他提到这种方法效率更高。这样调用 .cfm 我们不会在每次调用时都创建新实例。另一种方式,如果我们使用 .cfc 并调用函数,每次都会创建新实例。我不知道屏幕和 ColdFusion 深层背后的一切。

他提到的另一件事是这样更好,因为我们不使用任何框架。在过去的 4 年里,我一直在使用 ColdFusion,我过去看到的是 JQuery Ajax 使用特定的 method 名称调用 component.cfc。数据是 returned 并且 table 是动态构建的。我想知道是否有人对此了解更多,以及为什么 .cfm 可能比调用 .cfc 更好。

谢谢。

求评论

我同意其他人所说的。没有具体的答案,因为它总是依赖于比这段代码更多的东西。话虽如此...

我从 Adob​​e 文档 here 中找到了这个,它似乎是相关的。以下是该文档的摘录。我在 粗体 中突出显示了似乎相关的部分。注意 CFC 实例化之后的部分。您可以在 link.

阅读更多内容

When to use CFCs

You can use CFCs in the following ways:

  • Developing structured, reusable code
  • Creating web services
  • Creating Flash Remoting elements
  • Using asynchronous CFCs

Developing structured, reusable code

CFCs provide an excellent method for developing structured applications that separate display elements from logical elements and encapsulate database queries. You can use CFCs to create application functionality that you (and others) can reuse wherever needed, like user-defined functions (UDFs) and custom tags. If you want to modify, add, or remove component functionality, you make changes in only one component file. CFCs have several advantages over UDFs and custom tags. These advantages, which CFCs automatically provide, include all of the following:

  • The ability to group related methods into a single component, and to group related components into a package
  • Properties that multiple methods can share
  • The This scope, a component-specific scope
  • Inheritance of component methods and properties from a base component, including the use of the Super keyword
  • Access control
  • Introspection for CFC methods, properties, and metadata
    CFCs have one characteristic that prevents them from being the automatic choice for all code reuse. It takes relatively more processing time to instantiate a CFC than to process a custom tag. In turn, it takes substantially more time to process a custom tag than to execute a user-defined function (UDF). However, after a CFC is instantiated, calling a CFC method has about the same processing overhead as an equivalent UDF. As a result, do not use CFCs in place of independent, single-purpose custom tags or UDFs. Instead, use CFCs to create bodies of related methods, particularly methods that share properties. For more information about UDFs, custom tags, and other ColdFusion code reuse techniques, see Creating ColdFusion Elements.

Creating web services

ColdFusion can automatically publish CFC methods as web services. To publish a CFC method as a web service, you specify the access="remote" attribute in the method's cffunction tag. ColdFusion generates all the required Web Services Description Language (WSDL) code and exports the CFC methods. For more information on creating web services in ColdFusion, see Using Web Services.

现在我并不总是信任 Adob​​e 文档,因为他们有一个坏习惯,就是将现有文档从一个版本转移到另一个版本。所以谁知道这最初是什么时候写的,是否仍然是真的。这是 Adob​​e 的 ColdFusion 特有的,Lucee 可能更擅长处理这个问题,但我不确定。

该文档也引用了该文档 - Selecting among ColdFusion code reuse methods。我也会在此处包含该信息。

The following table lists common reasons to employ code reuse methods and indicates the techniques to consider for each purpose. The letter P indicates that the method is preferred. (There can be more than one preferred method.) The letter A means that the method provides an alternative that is useful in some circumstances. This table does not include CFX tags. You use CFX tags only when it is best to code your functionality in C++ or Java. For more information about using CFX tags, see Using CFX tags.