471,859 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,859 software developers and data experts.

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.onreadystatechange = RespondFunction1();
...
ajaxFunction2();

}

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.

Also,

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 1310
pbmods
5,821 Expert 4TB
http.onreadystatechange = RespondFunction1();
Should be

Expand|Select|Wrap|Line Numbers
  1. http.onreadystatechange = RespondFunction1;
  2.  
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); };
  3.  
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
NeoPa
reply views Thread by NeoPa | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.