Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JQuery multiple GET request URL

 
Md Uddin
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the below JQuery example to initiates the GET request to the server:



here test.php is the URL where the request is going. Is there a good way to assign it for Multiple URL ?

Like, if I have 4 different URL (number of URL is not fixed) to send the request to ... what should I do?

Any help will be appreciated. Thank you.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make the url a variable and set the variable?

Eric
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That greatly depends on what determines which url is to be used and when. You haven't said. How can we guess?
 
Md Uddin
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:That greatly depends on what determines which url is to be used and when. You haven't said. How can we guess?


Sorry If I couldn't make my question clear. I am very new to JQuery.

I am trying to send multiple num of request to the server and get the response back. I need to do it from one Javascript code/file.

For example, I may have 4 urls to send the request to (does not matter when, as long as all the request sent) from one Javascript file with the JQuery code.

Is that possible ?

Thank you in advance.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You want to send 4 requests at one time?

Eric
 
Md Uddin
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:You want to send 4 requests at one time?

Eric


Is it possible to send 4 request at one time ?

Let me give some more details:

Suppose I have the following 4 URLs to send the request to:

1) http:/www.testURL1.com/someThing
2) http:/www.abc123.com/anyThing?param=test
3) http:/www.testxyz.com/Logout
4) http:/www.mySite.com/Login

Now, I would like to send the request to the above URL using JQuery code (but it need to be done from one single HTML file or Java Script).
(it may be not with the .get() function ... that was my initial guess)

Thank you.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well you are not going to be making Ajax calls to another domain from your website.

You will have to make separate calls for each URL. You can easily code one function that has the JQuery code in it with a variable for the url.

Eric
 
Md Uddin
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:Well you are not going to be making Ajax calls to another domain from your website.

You will have to make separate calls for each URL. You can easily code one function that has the JQuery code in it with a variable for the url.

Eric


Hello Eric, thank you for your reply.

That is fine (as you mentioned above). But I also have to wait till I get all the responses back

another questions is:
How do I capture all the responses in one variable (or one place) ?

[a sample code will be great for whole thing ... ]


Thank you in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jQuery allows you to create "global" handling function that will be invoked at a number of staged of an Ajax request. It's a fine mechanism for consolidating processing in one place.
 
Md Uddin
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:jQuery allows you to create "global" handling function that will be invoked at a number of staged of an Ajax request. It's a fine mechanism for consolidating processing in one place.


Could you please give me an example (May be something related to my problem) ?

Thank you.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the methods under Ajax Events.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic