I have the following being echoed from a custom wordpress post type by get-client-logos.php
[{
"name": "One",
"url": "http://localhost/wp-content/uploads/2012/10/random04-128x84.jpg"},
{
"name": "Two",
"url": "http://localhost/wp-content/uploads/2012/10/chuck_norris_random_fact_generator_6_3957_2224_image_2578-128x84.jpg"
}]
I’m trying to extract the urls from each json object like so:
$.getJSON('get-client-logos.php/', function (data) {
var items = [];
$.each(data, function(key, val) {
items.push('<img src ="' + val + '"/>');
});
console.log(items);
});
Upon console.logging, I get the following:
["img src ="[object Object]"/", "img src ="[object Object]"/"]
How does one return the value instead of the typeOf?
What you have is an array of objects and so the
$.eachis going to pass theindexand theobject.. Try below code.