i have json array
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.
i have json array
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.
Share Improve this question asked Aug 18, 2015 at 6:52 ar emar em 4442 gold badges6 silver badges18 bronze badges4 Answers
Reset to default 4you 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.
How about this:
console.log(Object.keys(data).map(function(value, index){ return data[value].uid; }));
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
var response = JSON.parse(data);
response.forEach(function(item){
console.log(item.uid);
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744834380a4596175.html
评论列表(0条)