【问题标题】:J query call VB Behind Code function to return json?Jquery调用VB的Behind Code函数返回json?
【发布时间】:2014-02-24 11:11:11
【问题描述】:

我正在尝试调用后台代码函数以将 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?{}

【问题讨论】:

  • 内部服务器错误意味着 VB 脚本有问题。能否直接在服务器上运行(或单步执行)以便查看错误详情?
  • 您不能调用直接页面函数,您必须创建 Web 服务,或者您必须使用 qurey 字符串调用页面并响应为 Json 格式字符串

标签: jquery ajax json vb.net get


【解决方案1】:

添加到vb页面:

导入 System.Web.Services

然后让函数共享Public Shared Function GetBushCampBooking() As string

然后让它成为一个网络方法:

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

【讨论】:

    猜你喜欢
    • 2015-12-06
    • 2012-03-23
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多