Solved

Question about prototype.js

Posted on 2006-11-29
6
524 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now