Skip navigation
Currently Being Moderated

why is cfreturn null?

Jun 28, 2012 5:15 AM

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");

        }

}

 
Replies
  • Currently Being Moderated
    Jul 2, 2012 12:54 AM   in reply to ion

    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?

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 2, 2012 8:44 AM   in reply to ion

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 2, 2012 11:20 PM   in reply to ion

    ion wrote:

     

    thanks, but actually no, the intention is to dispaly the file content as the innerHTML of a div, obviously not possible since the function gets a null, which means, it doesn't even get the cfreturn (blank or no blank, it just doesn't get anything)

    Your post has until now made it seem otherwise. You made it seem, to me at least, that the problem is that you were failing to get the alert! So, let me ask. Does the alert appear as expected?

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 2, 2012 11:46 PM   in reply to ion

    ion wrote:

     

    just to make sure everything else is ok, i've added a cfinvoke statement on my page, invoking the same function and passing the same parameters. it behaves exactly as expected, the return string from cfc gets displayed on the page using a cfoutput. it's strictly a proxy thing, the way that callbackhandler is supposed to work

    Did you do something like this?

     

    <script>

    ...

    ...

     

    function ftpSuccess(ftpReturn)

    {

        document.getElementById('result').innerHTML = ftpReturn;

    }

     

    ...

    ...

    </script>

     

    <!--- Within body of page --->

    <div id="result"></div>

     

    If so, what was the result?

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 3, 2012 9:24 PM   in reply to ion

    ion wrote:

     

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

    [...]

    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"

    [...]

    if i remove the conditional and simply try to set the innerHTML, i get a http array with 2 elements:

    0  null

    1  undefined (and of course is not setting the innerHTML)

    Hi ion,

     

    I'm confused.  Could you please run the following app, and let us know the JS alert message?

     

    Application.cfc

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

    component {THIS.name = "TestCFAjaxproxyCFC";}

     

    text.txt

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

    my text

     

    MyCFC.cfc

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

    component {remote string function myCFCFunction() {return fileRead(expandPath("./text.txt"));}}

     

    index.cfm

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

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

    <script type="text/javascript">

      function myCallbackHandler(result) {

          alert(result.length);

      }

      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();

      }

      myJSFunction();

    </script>

     

    Thanks,

    -Aaron

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 4, 2012 3:04 AM   in reply to ion

    ion wrote:

    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


    The lights flickered when I read this again. I was reminded of a recommendation I had seen somewhere to use the following function syntax instead:

     

    var getFTP = function() {}

    var ftpSuccess = function(ftpReturn) {}

     

    Could that be the solution?

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 5, 2012 11:34 AM   in reply to ion

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 5, 2012 12:47 PM   in reply to ion

    ion wrote:

     

    thanks again everybody for your help, best regards

    Very cool, glad it's working now!

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points