?
Solved

Question about prototype.js

Posted on 2006-11-29
6
Medium Priority
?
536 Views
Last Modified: 2012-06-22
Hello,

I am using prototype.js for my Ajax function. The call of the Ajax function is inside a loop and only happens inside if condition. when the condition is true, the Ajax code is executed and then from the server side I return a value, according to this value I need to set the value of array in the current index of the loop. Now problem is that by the time that the value is returned from the server side the value of the index is changed because the loop is still running. Is there a way to pause the loop until the Ajax execution is complete?

I hope was clear, if not just tell me

Many thanks

-dirar
0
Comment
Question by:Dirar Abu Kteish
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 18041364
Yes, there is a way to stop after every server call and wait for server response.
The third parameter in open( method, URL, async ) is for the wait option when set to boolean value: false
Look here: http://en.wikipedia.org/wiki/XMLHttpRequest

0
 
LVL 6

Author Comment

by:Dirar Abu Kteish
ID: 18041420
hello Zvonko ,

Thanks for the quick reply. But I'm not sure about it if this can be applied to prototype?

-dirar
0
 
LVL 8

Expert Comment

by:Autogard
ID: 18041455
Are you using the scriptaculous prototype.js?  If so you can find info on how to set the async at:

http://wiki.script.aculo.us/scriptaculous/show/Ajax.Updater
or
http://wiki.script.aculo.us/scriptaculous/show/Ajax.Request
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 51

Accepted Solution

by:
ahoffmann earned 500 total points
ID: 18043463
> Is there a way to pause the loop until the Ajax execution is complete?
only by breaking the core idea of HTTP protocol and using XMLHttpRequest in syncronous mode (as Zvonko suggested)
Well, you also may get rid of your loop and use an event driven programming in your javascript code, which continues what our loop is supposed to do after it receives the result of the XMLHttpRequest call.
0
 
LVL 6

Author Comment

by:Dirar Abu Kteish
ID: 18048373
Thanks a lot everybody for the responds

ahoffmann , I think recursion may work just fine. Just let me check it out..

-dirar

0
 
LVL 6

Author Comment

by:Dirar Abu Kteish
ID: 18057384
I am back finally I my function is working. I rewrote the code and wrote some nice recursion , but after spending two precious days I thought of a better solution :)

Thanks for all, I decided to give the points to ahoffmann since he opened my mind and got me out of the loop..

p.s. I would really like to see a solution working with syncronous, I have tried many codes but yet none of them worked

-dirar
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question