Quantcast
Viewing latest article 3
Browse Latest Browse All 44

Answer by Abd Abughazaleh for How do I return the response from an asynchronous call?

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.


Viewing latest article 3
Browse Latest Browse All 44

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>