2012-06-29 154 views
0
<WebMethod()> Public Shared Function gtet() As String 
    ... 
    Dim GET = uClass.GetSets(dbuser, dbparam1) 
    ... 
End Function 

$(document).ready(function() 
{ 
    data = { }; 
    var jsondata = $.toJSON(data); 
    $.ajax({ 
     type: "GET", 
     url: "index.aspx/gtet", 
     data: jsondata, 
     contentType: "application/json; charset=utf-8", 
     dataType: "text json", 
     beforeSend: function (xhr) 
     { 
      xhr.setRequestHeader("Content-type", 
         "application/json; charset=utf-8"); 
     }, 
     success: function (cget) 
     { 
      alert(cget); 
     }, 
     error: function (XMLHttpRequest, textStatus, errorThrown) 
     { 
      window.location.reload(); 

     } 
    }); 
} 

我這樣做正確的返回數據?我需要從Dim GET中取出字符串

+0

(無關)爲什麼在「contentType」選項中指定它時,您在beforeSend中設置「Content-type」標頭? – Ian

回答

0

發送json作爲參數。

data: { 
    "json": jsondata 
}, 

此外,請確保您的webmethod返回有效的json。

+0

我該怎麼做? –