Few things confusing a newbie while writing JavaScript

Discussion in 'Javascript' started by Oltmans, Mar 21, 2011.

  1. Oltmans

    Oltmans Guest

    Hi, I hope you're doing well. I'm not an expert JavaScript programmer
    and have few questions that I hope you can answer. I will really
    appreciate any help.

    1- My JavaScript code basically provides the user the ability to
    perform certain actions (let's call them A(), B() and C()) after
    login(). All these actions are happening asynchronously via Ajax. So
    after writing this code here is how my code looks like

    login()
    A()
    B()
    C()

    Problem is that login() is happening asynchronously(using Ajax) so I
    never know when login() is done working and A()/B()/C() must only
    execute after successful login(). But in my case, code first goes to
    login() and while login() is still working the code jumps to B() hence
    it's not working as desired.

    In a nutshell, I want to provide the user ability to code like this
    login()
    A()
    B()
    but A() should only execute once login() is done working. Any ideas on
    how to circumvent this situation? Please enlighten me. I will really
    appreciate all help.

    Thanks!
     
    Oltmans, Mar 21, 2011
    #1
    1. Advertising

  2. Oltmans schrieb:
    > All these actions are happening asynchronously via Ajax.
    > [...]
    > Problem is that login() is happening asynchronously(using Ajax) so I
    > never know when login() is done working and A()/B()/C() must only
    > execute after successful login(). But in my case, code first goes to
    > login() and while login() is still working the code jumps to B() hence
    > it's not working as desired.


    Read https://developer.mozilla.org/en/AJAX/Getting_Started or google for
    some other docs, there are many out there, to see some example code.

    You can
    * send ajax requests synchronously, but then everything will stop
    working until the response is there
    * set an event listener for the response. This is done by assigning a
    function to request.onreadystatechange which checks the current state
    and, when ready, calls A, B and C or sends the next request.

    Bergi
     
    Andreas Bergmaier, Mar 21, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PJ
    Replies:
    2
    Views:
    328
    Vincent V
    Jul 31, 2003
  2. neil
    Replies:
    5
    Views:
    361
  3. Eirik WS

    A few things remain unclear...

    Eirik WS, Feb 2, 2004, in forum: C Programming
    Replies:
    9
    Views:
    401
    Mark McIntyre
    Feb 3, 2004
  4. =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?=

    vs2005 publish website doing bad things, bad things

    =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?=, Oct 25, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    626
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Oct 25, 2006
  5. Wang Jian
    Replies:
    2
    Views:
    153
    Wang Jian
    Apr 7, 2009
Loading...

Share This Page