Jump to content


Photo

non AJAX function returns undefined


Best Answer kicken, 19 November 2013 - 10:07 AM

You're missing your return statements on lines 32 & 41. The return you have on line 8 should not have a ; after it, and should combine with line 9. Go to the full post


  • Please log in to reply
2 replies to this topic

#1 Muddy_Funster

Muddy_Funster

    Advanced Member

  • Members
  • PipPipPip
  • 2,993 posts

Posted 19 November 2013 - 05:51 AM

ok guys, I'm a little confuddled about this one.  I'm not overly good at js, but have the need to do little bits and pieces here and there.  I have tried to create a few functions that should, when run together, recursively check through the given string and replace certain key character combinations and replace them for a specific value, which would be determined by runtime variables in the actual finished script.  My problem is that no matter what I try, the function is returning "undefined" rather than the data it has processed.  I have a fiddle of this when you can see it in action located here : http://jsfiddle.net/jJBH6/1/ - forgive the alerts, they are my preferred method of debugging.  for those link shy, I have posed the offending functions underneath.  I would really love if someone could explain why this is not returning the data as expected.

function checkHotVar(data) {
    var cursor = data.indexOf(':{');
    alert("special char search result = " + cursor);
    if (String(cursor) == '-1') {
        alert("returning ---" + data);
        return String("bugger me");
    } else {
        return ;
        validateHotVar(cursor, data);
    }
}

function validateHotVar(cuStart, data) {
    alert("moved into validate function with a starting point of " + cuStart);
    cuStart = cuStart;
    var cuEnd = data.indexOf('}', cuStart);
    if (String(cuEnd) == '-1') {
        alert("end Marker Not Found");
        return data;
    } else {
        cuEnd = cuEnd + 1;
        alert(" end marker found at " + cuEnd);
        datastring = data;
        var control = datastring.substring(cuStart, cuEnd);
        switch (control) {
            case ":{uid}":
                var repWith = 1;
                alert("match found swaping with " + repWith);
                break;
        }
        alert("starting swap function");
        doHotSwap(data, control, repWith);
       
    }
}

function doHotSwap(data, rep, wth) {
    alert("performing swapout process, changing " + rep + " with " + wth);
    var neData = data.replace(rep, wth);
    alert("swap performed, data now reads ---\n " + neData + "\n --- going back to check again");
    checkHotVar(neData);

}

A simple password hash :

function makePass($word=''){
  $dbSalt = '$2a$07$'.substr(hash('whirlpool',$word),0,22);
  $dbPass = crypt($word, $dbSalt);
 return substr($dbPass,12);
}



My SQL/PHP Blog

#2 kicken

kicken

    Wiser? Not exactly.

  • Gurus
  • 2,667 posts
  • LocationBonita, FL

Posted 19 November 2013 - 10:07 AM   Best Answer

You're missing your return statements on lines 32 & 41. The return you have on line 8 should not have a ; after it, and should combine with line 9.
Recycle your old CD's, don't trash them!
Did I help you out?  Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7

#3 Muddy_Funster

Muddy_Funster

    Advanced Member

  • Members
  • PipPipPip
  • 2,993 posts

Posted 19 November 2013 - 10:37 AM

Thanks kick, that's done the trick.  My confusion came from the data being accurate going into each of the functions, because I was passing it in as parameters, but without the returns that you pointed out, it was never being released from the functions in a usable way.  My major mistake was thinking that the only point I needed to return the data was when I was breaking out of the functions altogether, rather than treating each function as needing to return the data independently.

 

Thanks for the insight kicken.


A simple password hash :

function makePass($word=''){
  $dbSalt = '$2a$07$'.substr(hash('whirlpool',$word),0,22);
  $dbPass = crypt($word, $dbSalt);
 return substr($dbPass,12);
}



My SQL/PHP Blog




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com