0

i am using for a username but due to something it is caching the results, if i place alerts between it returns me correct results but if i remove it just returns true if first time is true and so on

i did a change now to use return just after the status but i started getting undefined and that does make sense because i am returning nothing just coming out of the function

function checkUsername(username) {
        var breturn = true;
        alert(username);
        $.ajax({
            url : 'check.php',
            type : 'POST',
            data : {
                'username' : username
            },
            beforeSend: function() { 
                $('#results').html('Checking for Username...') 
            },
            dataType:'json',
            success : function(data) {
                $('#results').removeClass('success');
                $('#results').removeClass('danger');       
                if($.trim(data.status) == 1) {
                    $('#results').removeClass('success').addClass('danger').html(data.message);
                    breturn = false;
                    return breturn;
                } else if($.trim(data.status) == 0) {   
                    $('#results').removeClass('danger').addClass('success').html(data.message);
                    breturn = true;
                    return breturn;
                }
            },
            error : function(request,error) {
                alert("Request: "+JSON.stringify(request));
                breturn = false;
                return breturn;
            }
        });
    }
Neil
  • 23
  • 3
  • You cannot rely on modifying a variable outside a callback like this. – evolutionxbox Feb 11 '21 at 17:40
  • 1
    Does this answer your question? [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – evolutionxbox Feb 11 '21 at 17:40

0 Answers0