Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Question about prototype.js

Posted on 2006-11-29
6
Medium Priority
?
540 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…

610 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