2010-08-02 33 views
0

這裏是我的jQuery:HTTPGET失敗

$.ajax({ 
     type: 'GET', 
     url: '/services/Service.asmx/FamilyHistory', 
     data: JSON.stringify({ 
      userID: 10, 
      historyID: famid 
     }), 
     contentType: 'application/json; charset=utf-8', 
     dataType: 'json', 
     success: function(val) { 
      var famHist = val.d; 
      alert(famHist.ID); 
     }, 
     error: function() { 
      parent.$.jGrowl('<b>Failed</b>', 
       { 
        header: 'User Action:', 
        life: 3000 
       }); 
     } 
    }); 

我的班級:

public sealed class FamilyHistoryEntity 
{ 
    public string ID { get; set; } 
    public string RelativeName { get; set; } 
} 

我的Web服務:

[WebMethod(EnableSession = true)] 
    [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)] 
    public FamilyHistoryEntity FamilyHistory(int userID, string historyID) 
    { 
     return GetFamilyHistory(historyID, userID); // returns a FamilyHistoryEntity class 
    } 

問題是,我甚至不能讓它在web服務上做一個斷點,它只會引發錯誤的jquery ajax事件。

回答

1

爲什麼使用stringify函數?它看起來好像是在調用一個帶有字符串參數的方法,而不是你的方法的兩個參數。

也許我錯過了什麼?

編輯:特別是因爲你指定的contentType爲JSON

data: { userID: 10, historyID: famid }, 

:所以,你會在數據屬性更改爲。

+0

我們需要對json進行字符串化以將參數傳遞給asp.net webservice。 – 2010-08-02 09:24:04

+0

@Martin好的。那麼我們確定famid是一個字符串變量而不是int嗎? – spinon 2010-08-02 09:29:05

+0

確定數據部分工作,它通過web服務。但是當它返回值時,jquery拋出一個錯誤事件。我需要[序列化] C#類嗎? – 2010-08-02 09:30:33