(also the 'el' variable in your code is undefined.)
On Feb 11, 1:28 pm, saidbakr <[EMAIL PROTECTED]> wrote: > Hi, > > I think that my problem is complicated. I already done what you have > told me due to the following requirement: > > I have another function used for doing form validation which I named > it as formVal(). Inside formVal() I called avaChk() in a conditional > if statement i.e. > if (avaChk()){ .... > > I modified avaChk() by adding after alert('222) and alert('333') > return false and return true respectively. Calling avaChk() leads only > alert('111') and alert('444'). In other word avaChk() did not return > true or false it just return the code outside $.ajax. > > You may notice that the code $.ajax is placed inside success handler. > This is making me mad!!! > > Best regards, > Said Bakr > > On Feb 11, 5:44 am, "Karl Rudd" <[EMAIL PROTECTED]> wrote: > > > It's a easy misunderstanding to have when you first begin to use AJAX. > > > Remember that the first 'A' in AJAX stands for "Asynchronous". You ask > > the browser (via jQuery's ajax function) to retrieve a URL and you > > give it a function that it will call with the result when it has > > retrieved it. > > > The browser may take 50 milliseconds or 50 seconds to retrieve the > > URL, you can't be sure how long. > > > In the mean time the browser (and your JavaScript function) continues > > on its way. > > > So you must put all the code for handling the results in the "success" > > (or "error") handler function. > > > Does that help? > > > Karl Rudd > > > On Feb 11, 2008 1:59 PM,saidbakr<[EMAIL PROTECTED]> wrote: > > > > 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?- > > > Hide quoted text - > > > - Show quoted text -