我试图调用一个后台代码函数将json返回给jquery?
Public Function GetBushCampBooking() As string
Dim conn As New SqlClient.SqlConnection
conn.ConnectionString = ConfigurationManager.ConnectionStrings("conn").ConnectionString
Dim dt As DataTable = New DataTable()
Dim ds As DataSet = New DataSet()
Dim cmd As New SqlClient.SqlCommand("BushCampBookingsGet", conn)
cmd.CommandType = CommandType.StoredProcedure
Try
conn.Open()
Dim Adp As SqlDataAdapter = New SqlDataAdapter(cmd)
Adp.Fill(ds)
Catch ex As Exception
Finally
conn.Close()
End Try
dt = ds.Tables(0)
Dim json As String
json = GetJson(dt)
Return json
End Function
Jquery的:
$.ajax({
type: "GET",
url: "BushCamp.aspx/GetBushCampBooking",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(result) {
alert(result.d);
//$("#content").html(result.d);
}
});
我的错误:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
http://localhost:10131/Hlh_shares/Content/BushCamp/BushCamp.aspx/GetBushCampBooking?{}
答案 0 :(得分:0)
添加到vb页面:
Imports System.Web.Services
然后将函数共享Public Shared Function GetBushCampBooking() As string
然后将其作为一种网络方法:
<WebMethod()> _
Public Shared Function GetBushCampBooking() As string