Gil Gil - 2 months ago 6
Ajax Question

Get data from multiple objects from ajax api call

i have multiple objects as response from an api call with Ajax, how do i "print" the data that's inside the object?

$.ajax({
url: 'url',
dataType: 'json',
type: 'post',
contentType: 'application/json',
data: JSON.stringify( { parameters } ),
processData: false,
success: function( data ){
console.log(data); <- this log all objects, i want the info inside the objects
},
});


enter image description here

how do i print every single "variable" for each object, or storage on an array.

Answer

If you want only to see the data,

console.log(JSON.stringify(data,null,4));

If you want to use the data, you have to iterate over the array and access each object separately, or use come collection methods ( see libraries such as underscore or lodash (https://lodash.com/) )

Comments