I need to call a function which does async ajax call and the request is cross domain,
At jQuery documentation is written:
async (default: true) Type: Boolean By default, all requests are sent asynchronously (i.e. this is set to true by default). If you need synchronous requests, set this option to false. Cross-domain requests and dataType: "jsonp" requests do not support synchronous operation
I saw that there is $.when
but the function itself exits before the ajax request comes back.
function checkLoginData() {
var jsonData = JSON.stringify({"db": db, "username": username, "password": password});
var response;
$.ajax({
type: "POST",
url: "http://someURL/checkLogin.php",
data: {data: jsonData},
success: function (data) {
response = data;
if (response == '"Error"') {
return false;
} else {
return true;
}
},
error: function (jqXHR, textStatus, errorThrown) {
return false;
}
});
};
I'm not really familiar with promises and I would really appreciate if someone knows how to make this work
This function is boolean