Solved

AJAX Sequence Question

Posted on 2009-07-01
11
384 Views
Last Modified: 2012-05-07
Hi,
I would like to do the following and require expert's help on how to do so:

//Following psuedo-code will be implemented in JavaScript
For each URI in the list
  Call a Server's Web Service (WS) One & retrieve the data
  Send the data to another Server to perform some operations

Question1: Since it is all going to be in JS, is xmlHttpRequest the only good solution to call an URI?

Question2: Is AJAX a good approach to solve the above problem? Are there better solutions?

Reason I am hesitant with AJAX is that is aynchronous in nature - meaning it might not fit well to do actions in a sequence. Though one could use successHandler to build this sequence, I am not sure if overall approach is an elegant solution. Moreover, the above problem is very simple - to perform actions in a sequence in a complex problem gets trickier.

Any other suggestions on how to solve similar kind of problems, i.e. doing actions in a sequence with remote URI calls to get data.

Thanks,
K
0
Comment
Question by:Purdue_Pete
  • 4
  • 4
  • 3
11 Comments
 
LVL 9

Expert Comment

by:jmanGJHS97
Comment Utility
The simplest solution is to do this server-side.  However, if you wish to do it client-side, then AJAX is probably a good choice.  You will certainly want to build in success handlers, due to the asynchronous nature of the calls, as you mentioned.

Yes, AJAX can get messy when the steps get complex, but there are lots of libraries out there to help simplify things.  There does come a point, though, when you have to ask how much it's worthwhile to do everything client-side, given load on the page, complexity of the code, etc.
0
 
LVL 18

Expert Comment

by:Hube02
Comment Utility
As far as I know, what you are looking to do can't be done.

>>Call a Server's Web Service (WS) One & retrieve the data
>>Send the data to another Server to perform some operations

I could be wrong, but I believe that pages/scripts from one server cannot access pages/scripts on another server due to browser security restrictions. This could be a large hurtle in your task.

As in the above comment, I'd look for a way to do the communication with the remote server on the server-side with whatever server-side scripting you are using.
0
 

Author Comment

by:Purdue_Pete
Comment Utility
jmanGJHS97,
Unfortunately - this has to be implemented in the client-side. Can you recommend some libraries that can simplify?

Hube02,
I am developing browser add-on(firefox) and hence can retrieve data from one server, pass it to add-on which in-turn passes to another server. Again, Unfortunately - this has to be implemented in the client-side

K
0
 
LVL 9

Accepted Solution

by:
jmanGJHS97 earned 150 total points
Comment Utility
Here's a list of more libraries than you probably ever want to see.  Prototype is a pretty common one.  Rico is built on prototype, as are several others.

http://chandlerproject.org/bin/view/Projects/AjaxLibraries

Some other good ones:

http://code.google.com/apis/ajaxlibs/

EXTJS is good, as is JQuery.  I also hear good things about script.aculo.us.
0
 
LVL 18

Assisted Solution

by:Hube02
Hube02 earned 100 total points
Comment Utility
I missed the fact that it was an add-on.

What you need to do is this, very messy, but it can work.

You do an AJAX request for the first set of data, in the return handler for that call you would then make the next AJAX request, and repeat, each handler starting the request for the next item in the sequence.

Perhaps some of the handlers can actually be the same if the requests are similar. There would be some logistics to figure out how to keep track of where you are in the sequence.

If you're interested I have my own AJAX class I use that might help as far as building the handlers go. My class only handles the request and return of data and then I need to build out most of the return handlers myself anyway. You might not want to use mine, but, it may point you in the right direction if you can decipher my code. It is well commented with explanations (to me anyway)
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Purdue_Pete
Comment Utility
jmanGJHS97,
Yes, I am aware of these different libraries - but, which among them does it help with my above problem?

Hube02,
I am using a good AJAX class to take care of the handlers etc. - but, I am looking for an elegant solution implemented already that takes care of the above problem also.
0
 
LVL 9

Expert Comment

by:jmanGJHS97
Comment Utility
I don't know that there is a library designed to solve this specific problem.
0
 
LVL 18

Expert Comment

by:Hube02
Comment Utility
I believe that jamanGJH97 is correct. You're not going to find some pre-built solution for your specific requirements. It would simply be too specific for a framework. Frameworks are designed to be generic, one size fits all tools. In this case, you are an irregular and need to go to the "Big & Tall" shop.
0
 

Author Comment

by:Purdue_Pete
Comment Utility
jmanGJHS97 / Hube02,
I understand that these are frameworks, have lot of features and one of the features may solve the problem.

But, which ones specifically do you recommend that can either solve or at least assist with the above problem - as there are many ones available and don't have time to analyze all the ones?

jmanGJHS97 - you did name few from the list - which among those helps me with the problem?
0
 
LVL 9

Expert Comment

by:jmanGJHS97
Comment Utility
They all have pros and cons.  They're each designed to make AJAX easier and more powerful.  I am not intimately familiar with them all, but I would suggest maybe Rico or Prototype to start.

Others like EXTJS and JQuery are very powerful but can be quite cumbersome to learn.  I guess the best advice I could give would be to pick one and go with it.
0
 

Author Closing Comment

by:Purdue_Pete
Comment Utility
Good answers. Code Examples and comparisons would have helped more!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

772 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

12 Experts available now in Live!

Get 1:1 Help Now