我用下面的code得到一些JSON格式的数据:
I'm using the following code to get some json formatted data:
$.ajax({
type: "GET",
url: "MyService.svc/GetSomeData",
dataType: "text",
success: function (data, textStatus) {
alert("Test: " + data.toString());
},
error: function (xhr, textStatus, errorThrown) {
alert("Error: " + (errorThrown ? errorThrown : xhr.status));
}
});
数据成功地返回到该电话,它看起来是这样的:
Data is successfully returned to this call, and it looks like this:
{"d":"test data"}
我的猜测是,我可以按如下方法访问数据:
My guess was that I could access the data as follows:
var myData = data["d"];
不过,这似乎总是返回未定义。我在想什么来获取数据的单一字符串测试数据?
However this seems to always return "undefined". What am I missing to get the single string of data "test data"?
如果您尝试会发生什么 data.d
?
what happens if you try data.d
?