we know that only synchronous requests are executed with $ .ajax with the async option: false But I saw in the jQuery manual that "synchronous requests can temporarily block the browser by disabling any actions while the request is active." I have some questions, such as
I saw several answers saying to use callback () How can I get jQuery to execute a synchronous rather than asynchronous Ajax request? . How can I implement this for my function.
In the function below, if the request fails or the response is not returned. How can I process it. I can use "error:" or something like this. How can I improve this feature effectively, I mean using callback and error handling. They say that (we can never get a mistake and success with a request)
function empvalidate() {
var exists = false;
var empno = $("#empno").val();
if (empno != '') {
$.ajax({
url: "emp.php",
async: false,
dataType: "json",
data: {'param1': $("#param1").val(), 'empno': $("#empno").val()},
success: function (data) {
exists = data.status;
}
});
}
return exists;
}
source
share