async: false
I solved it by setting async
to false and restructure my Ajax call:
I set a global function called sendRequest(type, url, data)
with three parameters to be called every time everywhere:
function sendRequest(type, url, data) { let returnValue = null; $.ajax({ url: url, type: type, async: false, data: data, dataType: 'json', success: function (resp) { returnValue = resp; } }); return returnValue;}
Now call the function:
let password = $("#password").val(); let email = $("#email").val(); let data = { email: email, password: password, }; let resp = sendRequest('POST', 'http://localhost/signin')}}", data); console.log(resp);
Important Note in code is :
async: false
If this solution is not working with you, please note this may not working in some of browsers or jQuery versions.