Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 399
  • Last Modified:

AJAX Sequence Question

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
Purdue_Pete
Asked:
Purdue_Pete
  • 4
  • 4
  • 3
2 Solutions
 
jmanGJHS97Commented:
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
 
Hube02Commented:
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
 
Purdue_PeteAuthor Commented:
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
Technology Partners: 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!

 
jmanGJHS97Commented:
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
 
Hube02Commented:
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
 
Purdue_PeteAuthor Commented:
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
 
jmanGJHS97Commented:
I don't know that there is a library designed to solve this specific problem.
0
 
Hube02Commented:
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
 
Purdue_PeteAuthor Commented:
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
 
jmanGJHS97Commented:
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
 
Purdue_PeteAuthor Commented:
Good answers. Code Examples and comparisons would have helped more!
0

Featured Post

Technology Partners: 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!

  • 4
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now