任何有关如何解决以下问题的信息将不胜感激
我正在尝试使用 JSON 将数据从 javascript 文件传输到 VB.Net 应用程序。
javascript文件中的代码如下:
function TalkToServer() {
var formData = "{'firstname':'fname','lastname':'dgln'}"
$.ajax({
type: "POST",
url: "dataserver.aspx/Save",
data: "{'firstname':'fname','lastname':'dgln'}",
contentType: "application/json;charset=utf-8",
dataType: "json",
success: function (msg) {
alert('Hello');
},
error: function () { alert(arguments[2]); }
});
}
VB.Net代码如下:
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.Services
Imports System.Web.Script.Serialization
Imports System.Web.Script.Services
Imports System.Web.UI
Imports System.Web.UI.WebControls
Public Class dataserver
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False)> _
Public Function Save(ByVal formData As williedata) As returnMessages
'Public Function Save(ByVal name As String) As returnMessages
Dim a As String = formData.firstname
Dim b As String = formData.lastname
Dim mes As returnMessages
mes.returnParameters = "KLJN"
mes.recAction = "JKHJH"
Return mes
End Function
End Class
数据结构的定义如下:
Imports Microsoft.VisualBasic
Public Class williedata
Public lastname As String
Public firstname As String
End Class
但是 - 似乎从未达到 VB.Net 功能。以下错误不断出现:
内部服务器错误
我知道我做错了什么,但不知道是什么。
WCV