Need help with $.GetJson
I'm using Jquery with WCF, and I'm struggling with getting values when it's returned as arrays by the WCF service.
Here's my JQuery code:
$(document).ready(function () {
$('#Button1').click(function () {
alert('Getting Data....');
$.getJSON("http://localhost:21030/Service1.svc/GetData", { "strval": "1" }, function (data) {
// $.each(data.d, function (n, val) { alert(val); });
alert(data);
});
});
});
And here's the JSON that's actually returned by the WCF service...
{"d":["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46"开发者_如何转开发,"47","48","49","50","51","52","53","54","55","56","57","58","59","60","61","62","63","64","65","66","67","68","69","70","71","72","73","74","75","76","77","78","79","80","81","82","83","84","85","86","87","88","89","90"]}
How can I actually get this array and populate them as a list on the page??
Edit: If I keep a breakpoint on the alert(data)
,the breakpoint doesn't even hit that line. It does not seem to go beyond the $.getJSON
. Any ideas why?
Create an unordered list somewhere on your page, I'll assume #result_list
points to your ul
.
$(document).ready(function () {
$('#Button1').click(function () {
alert('Getting Data....');
$.getJSON("http://localhost:21030/Service1.svc/GetData", { "strval": "1" }, function (data) {
var results = data.d;
var $list = $("#result_list");
$.each(results, function (result) { $list.append('<li>' + result + '</li>'); });
});
});
});
精彩评论