Reputation: 4259
[{"Emp_name":"admin","GIN_no":"001","Mode":"1"},{"Emp_name":"MMMK","GIN_no":"1792","Mode":"1"}]
this is my json return from wcf service when accessed from browser http://localhost/ddd/hostedService.svc/getEmployee
like this.
when i tried to access the returned json from jquery the d object returns undefined. my ajax looks like this.
$(document).ready(function () {
$(function () {
$.ajax({
type: "GET",
url: "http://localhost/ddd/hostedService.svc/getEmployee",
contentType: 'application/json',
datatype: 'json',
success: function (data) {
alert(data);
myFunction(data.d);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
}
});
});
function myFunction(ajaxValue) {
alert(ajaxValue.Emp_name)
}
the alert data returns {object,object}.... like this.
i am not sure where i am missing. any ideas.
Upvotes: 1
Views: 2773
Reputation: 4259
Such a dumb fellow i am, the json is returning a set of data as you can see the first line as array, just i have to use an each function to iterate through it and i am able to see list. so here is the working code
var items = [];
$.each(data, function (key, val) {
items.push('<li id="' + key + '">' + val.Emp_name + '</li>');
});
$('<ul/>', {
html: items.join('')
}).appendTo('body');
});
Upvotes: 2