2

i have json array

enter image description here

and this is my code

 var conf_url = "https://192.168.236.33/confbridge_participants/conference_participants.json?cid=0090000007";

   getParticipant(conf_url, function(output){
        var uid = output.uid;
        document.write(uid);
        });

 function getParticipant(conf_uri, handleData) {
    $.ajax({
      type: "GET",
      url: conf_uri,
      dataType: "jsonp",
      jsonpCallback: 'callback',
      contentType: "application/javascript",
      success: function(data) {
        handleData(data);
     //   console.log(data);
      }
    });

  }

i want to get uid of each object

but my output is undefined . . What am i doing wrong ? Please help.

4 Answers 4

4

you have iterate through the object list to output the value. You are getting an object array.

so

data.forEach(function(obj){
    console.log(obj['uid'])
})

the following would output the uid.

Update

You are passing a callback function to the Ajax request. So just do the following way.

getParticipant(conf_url, function(data) {
    data.forEach(function(obj){
       document.write(obj['uid'])
    })
});

function getParticipant(conf_uri, handleData) {
    $.ajax({
        type: "GET",
        url: conf_uri,
        dataType: "jsonp",
        jsonpCallback: 'callback',
        contentType: "application/javascript",
        success: handleData(data);
    });
}

pass the callback function directly to the ajax success and you can access the data returned from the ajax inside the callback function.

Sign up to request clarification or add additional context in comments.

1 Comment

uhm . . how can i output it on my code getParticipant(conf_url, function(output){ var uid = output.uid; document.write(uid); }); ?
2

How about this:

 console.log(Object.keys(data).map(function(value, index){ return data[value].uid; }));

Comments

1

You need a loop to read the uid of each object. Your code now is reading the uid attribute on the Array object, that's why you are getting an undefined

Comments

1
var response = JSON.parse(data);
response.forEach(function(item){
    console.log(item.uid);
});

2 Comments

uhm . . how can i output it on my code getParticipant(conf_url, function(output){ var uid = output.uid; document.write(uid); }); ?
@biancamihai : actually you don't need to parse data to json since it already comes as json. the data type is set to json in the ajax request.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.