How to Call a CFC From Javascript

CFC is the name given to objects created by software engineers who use Microsoft's ColdFusion web programming language. Some developers working with additional languages such as JavaScript may need to convert their CFC objects into an object that can be detected and used by JavaScript code. Calling a CFC object in JavaScript requires you to convert it into a JavaScript object.

Instructions

    • 1

      Open the CFC object that you wish to convert in a plaintext editing application such as TextEdit, included in Mac OS X, or Notepad, which is included with Microsoft Windows. In the same screen, open a new text document next to the CFC object so that you can reference the object while you convert it to JavaScript in the new text document.

    • 2

      Change the initial CFC object to include a JavaScript class name, such as "jsexample". Note the inclusion of "jsclassname" in the line of code below, which would be used in a CFC object that needs to be read by JavaScript.

      <cfajaxproxy cfc="examplecfc" jsclassname="jsexamplej" />

    • 3

      Add a scrip language definition below the line of code in the step above that specifies JavaScript as the scripting language:

      <script language="javascript">

    • 4

      Include a specific function for the JavaScript object to call next -- for example:

      function checkmybox(cbox) {

    • 5

      Create the object in both ColdFusion and JavaScript at the same time by adding the following line of code:

      var cfcAsAjax = new jsobj();
      if (!cbox.checked) {ischecked=0}

    • 6

      Call the CFC object as a JavaScript function by adding the following line of code:

      cfcAsAjax.setChecked(cbox.value,checked);
      }
      </script>

    • 7

      Save the modified object that you created in the new text document window and insert it into the JavaScript application that needs to call the CFC object.

Related Searches:

References

Comments

Related Ads

Featured