首先,您需要使用以下 javascript 代码从客户端调用服务器
$.ajax({
type: "get",
url: "?ajax_mode=SaveMyData,
dataType: "json",
async: false,
data: { headerData: JSON.stringify(emp) },
cache: false,
success: function(data, textStatus) {
if (data.status == "success") {
}
else {
}
}
});
现在处理 savemydata 函数来保存员工的信息
Public Sub SaveMyData()
Dim objHeaderPostData As Dictionary(Of String, Object)
Dim strParams As String = Request("headerData")
Dim objOutput As New Ajax.BasicAjaxObjectOuput
Dim jsS As New JavaScriptSerializer : objHeaderPostData = CType(jsS.DeserializeObject(strParams), Dictionary(Of String, Object))
Dim strFirstName as string = CStr(objHeaderPostData.Item("FirstName"))
'' get same way other infor from object objHeaderPostData
Dim objOutput As New BasicOuputObject
Dim objCommand As New SqlCommand
Dim lstMyData As New List(Of MyData)
Dim objMyData As MyData
Dim objConn As New SqlConnection("Pass Connection String")
objCommand.CommandText = '' write insert or update command as per requirement
objCommand.Connection = objConn
objConn.Open()
objCommand.ExecuteScalar()
objOutput.errorMessage = ""
objOutput.obj = "Successfylly save record."
objOutput.strMessage = "success"
Dim objSerialiser As New System.Web.Script.Serialization.JavaScriptSerializer
HttpContext.Current.Response.Write(objSerialiser.Serialize(objOutput))
HttpContext.Current.Response.End()
End Sub
希望这会帮助你。
有关 json 的更多信息,您可以在此处访问我的博客