在 ASP.Net 4 中从 jQuery 访问 asmx 服务的结果?

发布于 2025-01-06 14:47:52 字数 951 浏览 3 评论 0原文

我无法访问从我的网络服务返回的结果。当我在 firebug 中监视它时,我可以看到返回的结果是正确的,但我不知道如何访问它们。我收到错误“引用未定义的属性 data.d”

这是调用该服务的代码:

<script type="text/javascript">
$(document).ready(function () {
$("#Button1").click(function () {
$.ajax(
{
contentType: "application/json",
dataType: "json",
type: "POST",
url: "service/myService.asmx/getGameTitles",
data: "{ 'Genre': 'JRPG' }",
complete: Success,
error: Error,
processData: false
})
});

function Success(data, status) {
$("#MainContent_Label1").html(data.d);
}
function Error(request, status, error) {
$("#MainContent_Label1").html(request.statusText);
}
});
</script>

这是我在 firebug 中监视调用时看到的内容:

d   ["Game 1", "Game 2"]

0   "Game 1"

1   "Game 2"

并且

Success()
data = Object { readyState=4, responseText="{"d":["Game 1","Game 2"]}", status=200, more...}
status = "success"

我不确定如何访问结果。有什么建议吗?

谢谢!!

I am having trouble accessing the results returned from my web service. When I monitor it in firebug, I can see that the results being returned are correct, but I'm not sure how to access them. I am getting an error "reference to undefined property data.d"

Here is the code that is calling the service:

<script type="text/javascript">
$(document).ready(function () {
$("#Button1").click(function () {
$.ajax(
{
contentType: "application/json",
dataType: "json",
type: "POST",
url: "service/myService.asmx/getGameTitles",
data: "{ 'Genre': 'JRPG' }",
complete: Success,
error: Error,
processData: false
})
});

function Success(data, status) {
$("#MainContent_Label1").html(data.d);
}
function Error(request, status, error) {
$("#MainContent_Label1").html(request.statusText);
}
});
</script>

This is what I see when I monitor the call in firebug:

d   ["Game 1", "Game 2"]

0   "Game 1"

1   "Game 2"

and

Success()
data = Object { readyState=4, responseText="{"d":["Game 1","Game 2"]}", status=200, more...}
status = "success"

I'm not sure how to access the results... any tips?

Thanks!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愁杀 2025-01-13 14:47:52

在成功处理程序中,您可以访问结果

function Success(data, status) {
 console.log(data.d[0]);
 console.log(data.d[1]);
}

in the sucess handler you can access the results as

function Success(data, status) {
 console.log(data.d[0]);
 console.log(data.d[1]);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文