we know that only synchrnous requests are done with $.ajax with an option of async:false But i have seen in the Jquery manual saying that "synchronous requests may temporarily block the browser disabling any actions while the request is active". I have some questions such as
I have seen some answers saying to use callback () How can I get jQuery to perform a synchronous, rather than asynchronous, Ajax request?. How can i implement this to my function .
In the below Function if the Request Fails or if the response doesnot return How can i handle it .I mean Can i use "error:" or some thing like that . How can I improve this Function efficently i mean using call back and error handling .It is said that (we can never have error and success call back with a request)
function empvalidate() {
var exists = false; // default return value is 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; // set status of existence to outer variable
}
});
}
return exists; // return actual value
}