Solved

Question about prototype.js

Posted on 2006-11-29
6
531 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
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…
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…

831 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