无法获得Web服务响应

时间:2011-03-17 08:16:05

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

我肯定犯了一个非常蹩脚的错误,但无法弄清楚在哪里......

这是我的网络方法

 [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 enter image description here

修改

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

所以我想这会使它成为跨域请求?

1 个答案:

答案 0 :(得分: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/

相关问题