2011-03-17 104 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