Skip to main content
Inspiring
June 28, 2012
Answered

why is cfreturn null?

  • June 28, 2012
  • 1 reply
  • 3366 views

i proxied a call to a cfc which does an ftp get to a local temp file. Then it reads the file and is  supposed to return the file content as a cfreturn string. i know the code works, when i pull it out of cfc into a regular cfm file it does exactly what is expected

however, in my proxy callBackHandler, the cfc return is null.

<cfajaxproxy cfc="ftpfunc" jsclassname="jsobj" />

function getFTP() {

...

var instance = new jsobj();

instance.setCallbackHandler(ftpSuccess);

instance.setErrorHandler(ftpError);

instance.setReturnFormat('plain');

instance.getJCL(lpar,remoteFile,userName,password);

}

function ftpSuccess(ftpReturn)

{

    if (ftpReturn.length==0)

// error thrown right here: "ftpReturn is Null"

        {

            alert("Your FTP Get returned a blank file");

        }

}

This topic has been closed for replies.
Correct answer itisdesign

i think i understand what happens, but i'm not really happy about it. The reason it works is you call the function right after you declare it. I guess this is kind of a substitute for the ajaxonload function. My problem is, i don't want the function to execute onLoad, because it needs some user selected values from the form, to pass as parameters to the cfc

if i do the same thing (call the function after declaring it), i get another "Null" error, this time about the form fields that haven't been set by user yet. after that, the function will work

can i prevent it from executing onLoad?

thanks again


ion wrote:

can i prevent it from executing onLoad?

Hi ion,

You're welcome, and yes.  Can you please try this:

Application.cfc

----------------------

component {THIS.name = "TestCFAjaxproxyCFC";}

text.txt

----------------------

my text

MyCFC.cfc

----------------------

component {remote string function myCFCFunction(required string myArg) {return fileRead(expandPath("./text.txt")) & '-' & ARGUMENTS.myArg;}}

index.cfm

----------------------

<cfajaxproxy cfc="MyCFC" jsclassname="myCFCJSObj" />

<script type="text/javascript">

  function myCallbackHandler(result) {

      alert(result);

  }

  function myErrorHandler(statusCode, statusMsg) {

      alert('Status: ' + statusCode + ', ' + statusMsg);

  }

  function myJSFunction() {

      var instance = new myCFCJSObj();

      instance.setCallbackHandler(myCallbackHandler);

      instance.setErrorHandler(myErrorHandler);

      instance.setReturnFormat('plain');

      instance.myCFCFunction(document.getElementById("myfield").value); 

  }

  //myJSFunction();

</script>

<cfform>

  <cfinput type="text" name="myfield" value="foobar" />

  <cfinput type="button" name="mybutton" value="submit" onclick="javascript:myJSFunction()" />

</cfform>

Clicking 'submit' should alert "my text-foobar".

Thanks,

-Aaron

1 reply

BKBK
Community Expert
Community Expert
July 2, 2012

ion wrote:

<cfajaxproxy cfc="ftpfunc" jsclassname="jsobj" />

function getFTP() {

...

var instance = new jsobj();

instance.setCallbackHandler(ftpSuccess);

instance.setErrorHandler(ftpError);

instance.setReturnFormat('plain');

instance.getJCL(lpar,remoteFile,userName,password);

}

Shouldn't lpar ,remoteFile, userName, password also be arguments of getFTP?

ionAuthor
Inspiring
July 2, 2012

they are, i didn't include the first part of the func, which gets those values from some form fields.

that part works, i know that because if i comment out the line  instance.setCallbackHandler(ftpSuccess) i can see in fireBug, under the http\Response tab the actual file content, which is "test"

that's why i don't get the "null" error, looks like there is some particular syntax that must be used in order to handle the return inside the proxy

BKBK
Community Expert
Community Expert
July 2, 2012

The intention seems to have been

  if (ftpReturn.length != 0) alert ('OK');

Or, to cover both eventualities,

if(ftpReturn.length==0)

{

     alert("FTP Get returned blank file");

}

else

{

     alert("FTP Get returned non-blank file");

}

Edited by BKBK