Problem with inner functions in Ajax

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sakthipro
    New Member
    • May 2007
    • 18

    Problem with inner functions in Ajax

    Hi,

    I have a problem while using one ajax function inside of another ajax function,

    ie,

    function ajaxFunction1()
    {
    ...
    ...

    http.onreadysta techange = RespondFunction 1();
    ...
    ajaxFunction2() ;

    }

    function ajaxFunction2()
    {
    ...
    ...
    http.onreadysta techange = respondFunction 2();
    }

    Here, my problem is,

    i expect the function ajaxFunction2() should invoke after the full execution of function RespondFunction 1();
    but, the actual result invoke the function ajaxFunction2() after invoking the function respondFunction 1() its not waiting for the ajaxFunction1() to complete fully.

    Also,

    if the respondFunction 1() is inside a for...loop,
    i get only the final iteration as a output,
    middle iterations are suspended.

    Suggest me this regards.
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Originally posted by sakthipro
    http.onreadysta techange = RespondFunction 1();
    Should be

    Code:
    http.onreadystatechange = RespondFunction1;
    If you use RespondFunction 1(), the browser will execute RespondFunction 1 and use the result.

    If you needed to pass extra parameters to RespondFunction 1, do something like this instead:

    Code:
    var extraArg = 'test';
    http.onreadystatechange = function(response) { return RespondFunction1(response, extraArg); };

    Comment

    Working...