problem with asynchronous HTTP GET requests
Hey to all! This is my first post here!
I have used this forum a lot of times for some problems that I had
with jQuery. Now it's time to make my first question :)) here it is:
I use the ajax library to make some asynchronous HTTP GET requests.
What I want to do is to make asynchronous requests with different inputs
and to integrate the results into the HTML whenever they'll come. Here is my code:
- var params=new Array();
- params[0]=2;
- params[1]="type_3";
- $.get('http://localhost/my_page_1.php', params, function(data) {
- $('.result').html(data);
- alert("the id of the request is " + params[0] + "and its type is " + params[1]);
- });
- params[0]=3;
- params[1]="type_7";
- $.get('http://localhost/my_page_2.php', params, function(data) {
- $('.result').html(data);
- alert("the id of the request is " + params[0] + "and its type is " + params[1]);
- });
The problem here is that finally these requests will output the same message:
"the id of the request is 3 and its type is type_3".
But I want each request to happen based on its parameters that are set before,
so as the messages to be:
"the id of the request is 2 and its type is type_3", for the 1st one and
"the id of the request is 3 and its type is type_7", for the second one.
I want to do it with many more than two requests..
Can anyone help me to solve this problem?
Thank you in advance,
Thanasis