jquery - Making a variable in Javascript from AJAX return Value -


i scanned lot of pages here didn't find answer. i'm new php , javascript , seeking create variable (for comparison purpose) jquery return value. i'm creating registration system use check username availability:

$(document).ready(function() {     $("#username").keyup(function (e) {          //removes spaces username         $(this).val($(this).val().replace(/\s/g, ''));          var username = $(this).val();         if(username.length < 2){$("#user-result").html('');return;}          if(username.length >= 2){             $("#user-result").html('<i class="fa fa-refresh fa-spin"></i>');             $.post('core/check_username.php', {'username':username}, function(data) {              $("#user-result").html(data);             });         }     });  }); 

i can display return value in span form validation purpose, need compare return value set of criteria. can please me in declaring variable return value? in advance.

in $.post function data returned ajax-call. use further stuff username:

$.post('core/check_username.php', {'username':username}, function(data) {     $("#user-result").html(data);      var username = data;      if(username == "xxx")     {         // stuff here     } }); 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -