我有一个对 webmethod 的 ajax 调用,但调用总是失败。这是下面需要的代码。LetterReportDataStore 类进入数据库并填充并返回一个数据表。
$(document).ready(function () {
BindGridView('eastern');
});
function BindGridView(r) {
$.ajax({
type: "POST",
url: "AgencyLetterReport.aspx/GetLetterReportData",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert('Success');
for (var i = 0; i < data.d.length; i++) {
$("#grdviewe").append("<tr><td>" + data.d[i].Username +
"</td><td>" + data.d[i].Name + "</td></tr>");
}
},
error: function () { alert('Failed'); }
})
}
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Shared Function GetLetterReportData() As LetterReportData()
Dim region As String = "eastern"
Dim list As List(Of LetterReportData) = New List(Of LetterReportData)
Dim dt As DataTable = LetterReportDataStore.LoadGridData(region)
For Each r As DataRow In dt.Rows
Dim _data As LetterReportData = New LetterReportData
_data.Username = r.Item(0)
_data.Name = r.Item(1)
list.Add(_data)
Next
Return list.ToArray()
End Function