RonanC
RonanC

Reputation: 909

How to Populate multiple divs using jQuery's ajax?

I was trying to get my head around jQuery's Ajax. I have a page made up of a number of divs. I also have an XML document generated from a MySql resultset.

In the jQuery function below I am able to populate the titleDiv with data. The question I have is how do I populate the other divs on the page without having to build the page from scratch? I hope this makes sense......

$(document).ready(function() {
    $("#getData").click(function(){
        var data = "";
        $.get("phpAjax.php", function(theXML){
            $('row',theXML).each(function(i){
                var title = $(this).find("Title").text();
                var rating = $(this).find("Rating").text();
                data = data + title; 
            });
            $("#titleDiv").html(data);
            $("#ratingDiv").html(?????);
        });
    });
});

Upvotes: 1

Views: 1697

Answers (1)

xkeshav
xkeshav

Reputation: 54016

did u try with?? first decalre variable

 var title='';
 var rating ='';

& then inside each

   title+ = $(this).find("Title").text();
   rating+ = $(this).find("Rating").text();

    $("#titleDiv").html(title);
    $("#ratingDiv").html(rating);

Upvotes: 1

Related Questions