【问题标题】:cannot get the web service response无法获得 Web 服务响应
【发布时间】:2011-03-17 08:16:04
【问题描述】:

我肯定犯了一个非常蹩脚的错误,但不知道在哪里......

这是我的网络方法

 [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public int Add(int x, int y) {

            return x + y;

        }

我像这样通过 ajax 调用它

 $.ajax({
            type: "GET",
            dataType: 'json',
            contentType: "application/json; charset=utf-8",
            data: { x: 4, y: 5 },
            url: 'http://localhost:14436/Service1.asmx/Add',
            success: function (data) {
                alert('success');
                var d = $(data);
                console.log(d);        


            }
        });

问题是我无法在success 中获取返回的数据,

在提琴手中显示{"d":9},但我不断得到data 空...我在这里做错了什么... TIA

编辑

我的网络服务位于http://localhost:14436/Service1.asmx,我从中访问网络服务的网络应用程序位于http://localhost:3587/

所以我猜这使它成为一个跨域请求?

【问题讨论】:

  • 您已设置 contentType: "application/json; charset=utf-8",但您正在使用 XML。

标签: web-services jquery asp.net-ajax


【解决方案1】:

尝试以下功能:

function AjaxSucceeded(result) 
{
  alert(result.d);
}  

还是没有结果?
更新:
您可以阅读更多关于 .d 包装器的信息:
http://encosia.com/2009/02/10/a-breaking-change-between-versions-of-aspnet-ajax/

这是您想要实现的确切示例:
http://www.joe-stevens.com/2010/01/04/using-jquery-to-make-ajax-calls-to-an-asmx-web-service-using-asp-net/

【讨论】:

    猜你喜欢
    • 2015-11-14
    • 1970-01-01
    • 2012-05-01
    • 2014-08-09
    • 1970-01-01
    • 1970-01-01
    • 2017-06-24
    • 2020-06-12
    • 1970-01-01
    相关资源
    最近更新 更多