weardstuff
weardstuff

Reputation: 807

Ajax jquery json array output problem

When i get an json_encoded array with ajax json, i'm output the elements like the usual array

element[0]

$.ajax({                                      
  url: 'url.php',                
  data: "",                                       
  dataType: 'json',                    
  success: function(element)        
  {   
    $('#content').html(element[0]);
  } 
});

I get the infro from encoded json thtat is in the url, but it only outputs [object Object]

Upvotes: -1

Views: 353

Answers (2)

alex
alex

Reputation: 490567

That is because the toString() of an object returns [object Object].

You need to decide how to output that Object. Check its properties, and choose the ones you need, e.g. element.something.

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1039428

Well maybe there are some properties for this element. For example if the returned JSON looked like this:

[ { "someProperty": "value 1" }, { "someProperty": "value 2" } ]

you could:

$('#content').html(element[0].someProperty);

Upvotes: 2

Related Questions