Solved

Question about prototype.js

Posted on 2006-11-29
6
533 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:dxz2
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:dxz2
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 125 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:dxz2
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:dxz2
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

749 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