Well, if you want to load 3 different bits of data to put in 3 different
places all at once, first you've got to get your server to return the 3
little bits of datas in only one query and wrap them in containers so you
recognize them. So let's assume your unique query returns its results this
way :

<houses>
<house id="of straw"> a little piggy </house>
<house id="of_wood"> another little piggy </house>
 <house id="of_bricks"> this clever little bastard piggy </house>
</houses>

Now let's bring them where they belong.

$.ajax({
url: '/come_to_me_little_piggies.asp',
data: { or_i_will: 'huff', and: 'puff' },
cache: false,
success: function(piggies) {
// I'm real hungry, so the first one will end up in my stomach
$('#my_stomach').html($('house.of_straw', piggies).html());

// now I'm not so hungry so the second little piggy I'll keep for tomorrow
$('#leftovers').html($('house.of_wood', piggies).html());

// seems like this house of bricks was no match for mr wolf after all, let's
put little smartass in the cold room
$('#cold room').html($('house.of_bricks', piggies).html());
}
});

But the important thing is if you don't want to do 3 queries, you've got to
return all data in just one query.

Michel Belleville


2009/12/9 kingunderscore <brad.kings...@gmail.com>

> First of all i am working in ASP.  And i have 3 elements i am trying
> to populate.  I can do that no problem, but my issue is I am basically
> making the same Ajax request 3 times and there is SQL involved that i
> would rather only make once.
>
> I have pseudo code below to represent what i am doing.  If i could
> just make one call and pull topData, LeftData, and gridData that would
> cut the processing down significantly.
>
> $j.ajax({
>          url: '/ajaxHandler.asp',
>          data:  {handleSection:["top"],searchTerm:[''+searchTerm]},
>          cache: false,
>          complete: function(){
>                  $j.ajax({
>                  url: '/ajaxHandler.asp',
>                  data:
>  {handleSection:["left"],searchTerm:[''+searchTerm]},
>                  cache: false,
>                  beforeSend: function(){
>                  },
>                  complete: function(){
>                  },
>                  success: function(html){
>                          leftData = html;
>
>                          $j.ajax({
>                                  url: '/ajaxHandler.asp',
>                                  data:
>  {handleSection:["grid"],searchTerm:[''+searchTerm]},
>                                  cache: false,
>                                  beforeSend: function(){},
>                                  complete: function(){
>                                  },
>                                  success: function(html){
>                                        gridData = html;
>
>                                       // populate sections
>                                         $j("#top").html(topData);
>                                         $j("#left").html(leftData);
>                                         $j("#grid").html(gridData);
>                                  }
>                                });
>                  }
>                });
>          },
>          success: function(html){
>                topData = html;
>          }
>        });
>

Reply via email to