gpt4 book ai didi

javascript - 将数据从 javascript 文件导入到 VB.Net 页面

转载 作者:行者123 更新时间:2023-11-28 09:40:55 27 4
gpt4 key购买 nike

任何有关如何解决以下问题的信息将不胜感激

我正在尝试使用 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

最佳答案

您的数据参数需要与方法签名更匹配:

data: '{"formData":{"firstname":"fname", "lastname":"dgln"}}'

您可以use JSON.stringify to simplify that process .

关于javascript - 将数据从 javascript 文件导入到 VB.Net 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12430014/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com