• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 570
  • Last Modified:

cfcAsAjax not recognizing function

I have the following above my script block:
<cfajaximport>
<cfajaxproxy cfc="com.prodServ" jsclassname="jsObj" />

Open in new window


When I attempt to access the following function, I get an error:
<script type="text/javascript">
	<!---save content function--->
	function saveContent() {
		var index = document.selectService.service.selectedIndex;
		var content = $( 'textarea.contentEditor' ).val();
		var cfcAsAjax = new jsObj();
		cfcAsAjax.updateElement();//id=index,content=content
		return false;
	}
</script>

Open in new window


The error (retreived from firebug/console) is as follows:

cfcAsAjax.updateElement is not a function
     var cfcReturn = cfcAsAjax.updateElement();//id=index,content=content
0
brianmfalls
Asked:
brianmfalls
  • 5
  • 5
2 Solutions
 
_agx_Commented:
> cfcAsAjax.updateElement();//id=index,content=content

Are you sure it's the right object. Create an instance of the cfc and dump it. Do you see a function named updateElement()?

      <cfset obj = createObject("component", "com.prodServ")>
      <cfdump var="#obj#">

If yes, try making the function access="public"
<cffunction name="updateElement" access="public" ...>

     > <cfargument name="id" required="yes">
    >      <cfargument name="content" required="yes">

Lastly, if the parameters are required, you must pass them in or you'll get an error.
      cfcAsAjax.updateElement( id, content );//id=index,content=content

0
 
srikanthmadishettiCommented:
Did you set your function updateElement access attribute  to remote
0
 
_agx_Commented:
> If yes, try making the function access="public"

Gah... I meant to say remote.  Sri's right.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
srikanthmadishettiCommented:
@agx - I saw your comment only after posting my comment :) .

For cfajaxproxy the access attribute of function need to be set to remote .
0
 
srikanthmadishettiCommented:
@agx- Again i saw your this comment 10/11/11 01:56 AM, ID: 36944978 after posting my comment 10/11/11 01:57 AM, ID: 36944984  :)
0
 
_agx_Commented:
Yeah, but you're still right ;-)
0
 
srikanthmadishettiCommented:
you can set error handler in the js like this


<script type="text/javascript">
      <!---save content function--->
      function saveContent() {
            var index = document.selectService.service.selectedIndex;
            var content = $( 'textarea.contentEditor' ).val();
            var cfcAsAjax = new jsObj();
        cfcAsAjax.setErrorHandler(myErrorHandler);
            cfcAsAjax.updateElement();//id=index,content=content
            return false;
      }
      
      function myErrorHandler(statusCode, statusMsg)
            {
                alert('Status: ' + statusCode + ', ' + statusMsg);
            }
</script>
0
 
_agx_Commented:
    >  cfcAsAjax.updateElement();//id=index,content=content

But remember that function has 2 required arguments. So you can't skip them. You must pass in a value.

       ie cfcAsAjax.updateElement( argOneHere, argTwoHere );

    > you can set error handler in the js like this

Or you can just set it in the cfajaxproxy tag ;-)

<cfajaxproxy
    bind = "bind expression"
    onError = "JavaScript function name"
    onSuccess = "JavaScript function name">
0
 
brianmfallsAuthor Commented:
Thanks guys...
0
 
srikanthmadishettiCommented:
@agx - please clarify on this
when we are using cfc attribute we cannot use onerror  and onsuccess so we need to use
setCallbackHandler and setErrorHandler and pass the javascript function as the parameter which needs to be called .

erorrhandler function which is given as an argument to setErrorHandler need to accept 2 parameters statusCode, statusMsg which is sent by the call it self no need to pass them  same with setCallbackHandler The callback function must take one parameter, the return value from the CFC is sent to that parameter by the call
0
 
_agx_Commented:
Yep, my bad.  I'm mixing threads!  
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now