json returns [object Object] instead of actual data
I have refered many questions on stack overflow and on other sites for the
solution. But everywhere I got incomplete answer. some answer says log the
json data to console. So I tried it and there I get the json object
correctly. But when I add it to HTML or alert it says [object Object].
There are many duplicates of this question but still I dont understand
what the problem is? Here is my code so far
$(document).click(function () {
$.ajax({
type: "POST",
url:
"/members/ListOfAllOppositeTypeUsersWithTheirRespectiveData?LoggedInUserOppositeType=2",
dataType: 'json',
success: function (json) {
console.log(json);
var strJson = JSON.stringify(json);
$.each(json, function (key, value) {
$('#AllowedFriends').append($('<option value="'+ key +
'">' + value + '</option>'));
});
},
error: function () {
alert("F");
}
});
});
No comments:
Post a Comment