[jQuery] Using jQuery inside an ordinary function notes!
Hi,
I have very little knowledge about javascript. I used it with ordinary
functions and the code of jquery may make me confused.
I used it in a javascript function some thing like that:
<script>
function avaChk(lnk,id){
alert('111')
ob = document.getElementById('id');
$.ajax({url: 'chk_user.php',type:'GET', data: id+'='+ el, cache:
false, dataType: "script", success: function(data, textStatus){
if (data == 0){
alert('222');
}
else{
alert('333');
}
},
error: function(x,txt,err){
$("#waitImg"+lnk).remove();
alert('Could not check...'+"\n"+'The server may down or busy. Retry
again after a while.');
}
});
alert('444');
}
What I noticed is, when I call the function avaChk(), for me, very
strange thing is happened. ;) I think the jQuery proffesional will
know it:
The alert sequence as I respect is 111, 222 or 333 then 444
what happened is not like above, it was 111,444, 222 or 333 !!!
I respected that the jQuery code should be executed before the
alert(444). In real world this prevent me from using the value of data
or return it through another function.
What's wrong in my understanding and how can I overcome this problem?