AJAX calls are asynchronous, which means that they only return data after the operation completes. That is, the checkusernameavailable method never returns any information (unless you specify it inside the method itself). You need to do the following:
// Just fire and forget the method checkusernameavailable("userName"); // Change the success function to do any display you require success: function(response) { alert(response); $("
The method runs the asynchronous AJAX method, which is sent to check.php. When the answer is received, you then process that response in the function associated with the success $.ajax . You can also specify a function directly for this callback:
// Change success to point to a function name success: foo // Create a function to handle the response function foo(response) { // Do something with response }
EDIT:
According to the OP comment, you need to change your AJAX call as synchronous, not asynchronous (I never made a synchronous call like this myself, so it has not been verified):
var ajaxResponse; $.ajax({ async: false, success : function (response) { ajaxResponse = response; },
Full list of APIs here .
GenericTypeTea Oct 07 2018-10-10T00: 00Z
source share