我正在尝试了解如何在asp.net页面上查看从Web方法返回的json数据。该方法有效,但是我不确定如何查看数据。最终,我将这些数据绑定到一张世界地图上。这是代码块
$( document ).ready(GetCountryData);
function GetCountryData() {
$.ajax({
type: "POST",
url: "Test.aspx/PopulateCountries",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function(response) {
alert("Failure " + response.d);
}
});
}
function OnSuccess(response) {
alert("Succuess " + response.d);
}
这是网络方法
<WebMethod>
Public Shared Function PopulateCountries() As String
Dim temp As String = Nothing
Dim Product As New ProductsBLLWithSProcs
Dim ds As New CountryBLLWithSProcs
Dim dt As LocationsDataTable = ds.GetCountriesWithProducts
Try
temp = ToJSONRepresentation(dt)
Catch ex As Exception
End Try
Return temp
End Function
Public Shared Function ToJSONRepresentation(dt As LocationsDataTable) As String
Dim sb As StringBuilder = New StringBuilder()
Dim jw As JsonWriter = New JsonTextWriter(New StringWriter(sb))
For Each row As LocationsRow In dt.Rows
jw.Formatting = Formatting.Indented
jw.WriteStartObject()
jw.WritePropertyName("id")
jw.WriteValue(row.locCountry)
jw.WritePropertyName("name")
jw.WriteValue(row.locName)
jw.WritePropertyName("quantity")
jw.WriteValue(row.Quantity)
jw.WriteEndObject()
Next
Return sb.ToString()
End Function
如何使用console.log方法或警报方法查看结果。感谢您的指导