2014-02-24 21 views
0

我想調用一個後臺代碼函數來返回一個JSON到jQuery?查詢調用VB Behind Code函數返回json?

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

內部服務器錯誤意味着有與VB腳本的一個問題。你可以直接在服務器上運行它(或通過它),以便你可以看到錯誤細節? – Archer

+0

你不能調用直接頁面函數你必須創建Web服務或者你必須使用qurey字符串調用頁面並響應As Json格式字符串 –

回答

0

添加到VB頁:

Imports System.Web.Services

然後使本功能離子共享Public Shared Function GetBushCampBooking() As string

然後讓一個WebMethod:

<WebMethod()> _ 
Public Shared Function GetBushCampBooking() As string