tags:

views:

37

answers:

2

Ok so i have the json object returned back from my script and I have all the data but how do I put it on the page. Here is what i have so far

I have a php page which has a loop like this

<div class="main-blue">
<div class="blue-items">
<?php foreach ($related as $row_r) { ?>
<div class="item-blue">
<div class="image left">
<img src="<?php print $row_r['image'] == "" ? "css/images/blue-png2.png" : "css/images/{$row_r['image']}" ?>" alt="" />

As you can see the Php loop is looping through the array $related which has lots of products. I have an ajax call that can change the data in this array and regenerate the page. I have the new data from a getjson call

 $.getJSON('function.php?type=piz&count=5', function(data) {
 $(data).each(function(key, value) {
   console.log(value);
   });
});

How do i recreate the page using the new data

+1  A: 

What I think you're talking about is client side templating. Rick Strahl has a good write up on the concept: http://www.west-wind.com/weblog/posts/509108.aspx

Eric
A: 

Your JS.
$.getJSON('function.php?type=piz&count=5', function(data) { $(data).each(function(key, value) { $('#contentHere').html(value); }); });

your html

<div id="contentHere"></div>
Martin Ongtangco
Won't this code just replace the contents of the "contentHere" element over and over and over again and just leave it with the last element's value? I know what you are driving at here, but this code, as it stands, will just confuse the OP further.
Lucanos
this is basically just a short explanation. if he'll get confused, then he'll learn. I'm not here to spoon feed.
Martin Ongtangco