有關如何解決以下問題的任何信息,將不勝感激進口數據從javascript文件到VB.Net
我試圖將數據從一個JavaScript文件傳送到使用JSON一個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函數似乎永遠不會達到。以下錯誤不斷appering:
內部服務器錯誤
我知道我做錯了什麼,但無法弄清楚什麼。
WCV
你確定你的網址是'dataserver.aspx'而不是'dataserver.asmx'嗎?如果這是正確的,你是否嘗試調試並在你的方法中設置斷點? – marteljn
是的,它是dataserver.aspx,一個正常的asp頁面。我試圖在方法中設置一個斷點,但它永遠不會到達WCV – user1672071