【发布时间】:2013-11-14 01:39:16
【问题描述】:
我的 .asmx Web 服务返回成对的文件路径和文件名,如下所示:
[{"thumb":"path/image01_thumb.jpg","image":"path/image01.jpg"},{"thumb":"path/image01_thumb.jpg","image":"path/image01.jpg"}.....etc ]
我正在尝试遍历响应并获取每个元素的属性 thumb 和 image,但我在下面的所有尝试都失败了。
$.ajax({
type: "POST",
url: "mywebservice",
data: "{'startpath':'somepath'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (msg) {
$.each (msg, function (m) {
console.log("alert 3 " + m.thumb); // output: undefined
console.log("alert 4 " + m.image); // output: undefined
});
}
进一步调试...
console.log("alert 1 " + msg); //output: [object object]
console.log("alert 2 " + msg.d); //output: the entire response
如何遍历响应并获取上述值。我在 chrome 和 IE 9 中得到了相同的结果。卡在使用 Jquery 1.3.2 因为我使用的是 Galleriffic 库。
【问题讨论】:
-
它是一些对象的数组。如何在 JavaScript 中循环数组?把问题分解成小块..
标签: javascript json web-services web