[VB][jQuery][Ajax] 使用Ajax josn返回Server取值的方法

摘要:[VB][jQuery][Ajax] 使用Ajax josn返回Server取值的方法

上網查了一些範例,並手動測試看看,以下為簡單的使用方法,僅做紀錄之用。

後置程式碼的方法必須為靜態方法並宣告為WebMethod

AjaxGetValue.aspx




 

AjaxGetValue.aspx.vb


Imports System
Imports System.Web.Services
Imports System.Web.Script.Services

Partial Class AjaxGetValue
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    '必須為靜態方法

     _
    Public Shared Function getDataString() As String
        Return "Ajax取值測試"
    End Function

     _
    Public Shared Function getDataPar(ByVal str1 As String, ByVal str2 As String) As String
        Return str1 & "," & str2
    End Function

     _
    Public Shared Function getDataArray() As ArrayList
        Dim ary As New ArrayList
        For i As Integer = 0 To 5
            ary.Add("Ajax取值測試" & i)
        Next
        Return ary
    End Function

     _
    Public Shared Function getDataHashtable(ByVal isKey As String, ByVal isValue As String) As Hashtable
        Dim htbl As New Hashtable
        htbl.Add("col1", "Ajax取值測試c1")
        htbl.Add(isKey, isValue)
        Return htbl
    End Function
End Class

 

範例檔案: AjaxGetValue.rar

 

 

 


以上文章敘述如有錯誤及觀念不正確,請不吝嗇指教
如有侵權內容也請您與我反應~謝謝您 :)