2011-03-17 100 views
0

我肯定的犯一个非常蹩脚的错误,但无法弄清楚哪里...不能得到Web服务响应

这里是我的Web方法

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

      return x + y; 

     } 

和IM通过如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

编辑

我的web服务是http://localhost:14436/Service1.asmx,并从我的web应用程序即时通讯访问网络服务位于http://localhost:3587/

所以我想这使得它跨域请求?

+0

您已设置的contentType'“ application/json; charset = utf-8“'但你正在使用XML。 – 2011-03-17 08:21:41

+0

仍然不起作用 – Rafay 2011-03-17 09:00:59

回答

1

尝试以下功能:

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

仍然没有得到任何结果呢?
UPDATE:
您可以阅读更多有关.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/

+0

我已经尝试过但没有成功 – Rafay 2011-03-17 08:24:11