views:

61

answers:

2

I have this output from ajax call:

{"total":"3","data":[{"id":"4242","title":"Yeah Lets Go!","created":"1274700584","created_formated":"2010-07-24 13:19:24","path":"http:\/\/domain.com\/yeah"}]}

So there is three that kind of items in that array and I would need to go that through and print actual html out if. So on page it would:

Yeah Lets Go! (<which is a link to http:www.domain.com/yeah)
Created: 2010-07-24 13:19:24

Im clueles with this one. And yes, I don't know much javascript.

EDIT: also atm i get that raw output after clicking link. How can I get it to show on page load? Or it does that ajax call when I click link atm.

EDIT 2: I got it to output everything at once. But still I have a prolem with putting it actual html. The output atm is:

"total":"3","data":[{"id":"4242","title":"Yeah Lets Go!","created":"1274700584","created_formated":"2010-07-24 13:19:24","path":"http:\/\/domain.com\/yeah"}{"id":"4242","title":"Yeah Lets Go!222","created":"1274700584","created_formated":"2010-07-24 13:19:24","path":"http:\/\/domain.com\/yeah222"}{"id":"4242","title":"Yeah Lets Go!333","created":"1274700584","created_formated":"2010-07-24 13:19:24","path":"http:\/\/domain.com\/yeah333"}]}

I would like to get that into list with title and link and creation day.

+1  A: 

First off, that's a JSON string, you need to un-serialize the string into a real JavaScript object (look at json.org for this).

Once you have the native JavaScript data, something like this should work:

var html = '';
for(var i=0; i < obj.data.length; i++) {
    html += '<a href="'+obj.data[i].path+'">'+obj.data[i].title+'</a><br>';
    html += 'Created: '+ obj.data[i].created;

}
Luca Matteis
It's serialized as JSON and needs to be de-serialized.
Reinis I.
You are right..
Luca Matteis
A: 

Hmm, now im even more confused.

That JSON string comes out of this:

$('a.link').click(function() {
var item_id = $(this).attr("href").split('#')[1];
$.get(base_url+'/ajax/get_itema/'+item_id+'/0/3/true', null, function(data, status, xhr) {
$('#contentCell').html(data);
});

So I would need to do for that is something like:

var html = eval(data); 

and then I would do what Luca Matteis suggest?

mikeeyy
Can anoyne help, plz?
mikeeyy