469,315 Members | 1,417 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,315 developers. It's quick & easy.

Problem with inner functions in Ajax


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


function ajaxFunction1()

http.onreadystatechange = RespondFunction1();


function ajaxFunction2()
http.onreadystatechange = respondFunction2();

Here, my problem is,

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


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

Suggest me this regards.
May 5 '07 #1
1 1278
5,821 Expert 4TB
http.onreadystatechange = RespondFunction1();
Should be

Expand|Select|Wrap|Line Numbers
  1. http.onreadystatechange = RespondFunction1;
If you use RespondFunction1(), the browser will execute RespondFunction1 and use the result.

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

Expand|Select|Wrap|Line Numbers
  1. var extraArg = 'test';
  2. http.onreadystatechange = function(response) { return RespondFunction1(response, extraArg); };
May 6 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

57 posts views Thread by Xarky | last post: by
2 posts views Thread by Fernando Barsoba | last post: by
3 posts views Thread by willl69 | last post: by
3 posts views Thread by from.future.import | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.