0

I am using javascript in jsp to hide and show some labels. I'm using ajax to retrieve data from database and comparing it with a string.
In the below code I'm passing "1" as the parameter which is pass but it always goes to the else part. Am I doing something wrong?
I even tried with null but it also doesn't hit.

Here's my code actually:

$(document).ready(function() {
  var pass; //pass = 1
  $.ajax({
    url: 'ValidateUser',
    type: 'post',
    dataType: 'text',
    success: function(data) {
      var post = data;
      $("#username").append('<p>' + post + '</p>');

      pass = data;
    }

  });

  setAttributes(pass);
});

function setAttributes(pass) {
  if (pass === "1") {
    document.getElementById("ulUsername").style.visibility = "hidden";
    document.getElementById("ulCreateAccount").style.visibility = "visible";
  } else {
    document.getElementById("ulUsername").style.visibility = "visible";
    document.getElementById("ulCreateAccount").style.visibility = "hidden";
  }
}

Thank you in advance.

developer033
  • 24,267
  • 8
  • 82
  • 108
jayz
  • 401
  • 1
  • 5
  • 25

0 Answers0