Solved

AJAX Sequence Question

Posted on 2009-07-01
11
395 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
[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
  • 4
  • 4
  • 3
11 Comments
 
LVL 9

Expert Comment

by:jmanGJHS97
ID: 24755157
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
ID: 24755225
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
ID: 24755384
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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
LVL 9

Accepted Solution

by:
jmanGJHS97 earned 150 total points
ID: 24755478
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
ID: 24755509
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
 

Author Comment

by:Purdue_Pete
ID: 24755607
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
ID: 24756012
I don't know that there is a library designed to solve this specific problem.
0
 
LVL 18

Expert Comment

by:Hube02
ID: 24756201
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
ID: 24756500
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
ID: 24756523
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
ID: 31598790
Good answers. Code Examples and comparisons would have helped more!
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

730 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