ajax - What function instead jQuery async:false -
in old version of jquery. sometime use jquery ajax , set async:false wait response ajax. in present day, async:false deprecated. don't know how use other instead async:false. please suggest me.
[my code when use jquery ajax async:false]
function check(id) { var check = ''; jquery.ajax({ type : 'post', url : 'test.php', data : 'id='+id, cache:false, async:false, success:function(data) { if(data == 'good') { check = 'pass'; } else if(data == 'bad') { check = 'not_pass'; } } }); if(check == 'pass') { alert('pass'); } else if(check == 'not_pass') { alert('not pass'); } } in above code used async:false wait response test.php. after test.php not async:false deprecated.
async: false meant used rarely, because blocks user input while it's waiting response server. it's better handle result asynchronously, e.g.:
jquery.ajax({ type : 'post', url : 'test.php', data : 'id='+id, cache:false }) .done(function(data) { if (data == 'good') { alert('pass'); } else if (data == 'bad') { alert('not pass'); } }) .error(function() { //handle error... }); note i'm using new promises interface (the done() , error() callbacks). success , error options still work if prefer those.
Comments
Post a Comment