Liox
Liox

Reputation: 19

Javascript callback function does't fire up

for some reason callback doesn't fire up. I cut all the extra code out, this is the structure. Perhaps i can't see something wrong here?

(function() {
  registerSecendStep = new Page('registerSecendStep', function(name) { //CLIKED THE BUTTON
    $('.register-second-step-button').click(function() {
      function doAjax(testReferral) {
        alert(testReferral); //THIS NEVER GETS PRINTED
      }

      showHint(function() { doAjax(testReferral); }); //START THE CALL
    });
  });

  function showHint(callback) { //CALLBACK
    xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        alert('called'); //THIS GETS ALERTED
        callback(true);
      }
    }
    xmlhttp.open("GET", helper.app.HomeSite + "/ajaxresponder?w=" + str, true);
    xmlhttp.send();
  }
})();

Any help appreciated

Upvotes: 0

Views: 49

Answers (1)

Alan Friedman
Alan Friedman

Reputation: 1610

testReferral is never defined in the callback. Try:

showHint(function(testReferral) {doAjax(testReferral);});

Upvotes: 1

Related Questions