我正在尝试使用Ajax在服务器端进行计算。
通过jQuery,Ajax和Javascript将数据放回Default.aspx。
我正在使用Classes将webmethod函数中的数据发送回jQuery以及Ajax代码的结果。
通过Json数据输入WebMethod函数。
ajax webmethod函数的输出没有打印出来。
不确定错误的来源:
计算中的1-XML
Dim xmldoc0 = XDocument.Load("xml/file1.xml")
该功能不接受:
Dim xmldoc0 = XDocument.Load(Server.MapPath("~/xml/file1.xml"))
2-Ajax力学
Public Class planetClass
Public Property p1() As Double
Get
Return pl1
End Get
Set(value As Double)
pl1 = value
End Set
End Property
Private pl1 As Double
Public Property p2() As Double
Get
Return pl2
End Get
Set(value As Double)
pl2 = value
End Set
End Property
Private pl2 As Double
Public Property p3() As Double
Get
Return pl3
End Get
Set(value As Double)
pl3 = value
End Set
End Property
Private pl3 As Double
End Class
Default.aspx的
$(document).ready(function () {
$("#<%= Button1.ClientID %>").click(function () {
var data = { mo: '3', dy: '20', yr: '2017' };
var json1 = JSON.stringify(data);
$.ajax
({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: json1,
url: "Default.aspx/GetData",
success: function (result) {
$("#<%= TextBox1.ClientID%>").val(result[0].p1);
$("#<%= TextBox2.ClientID%>").val(result[0].p2);
$("#<%= TextBox3.ClientID%>").val(result[0].p3);
$("#<%= TextBox4.ClientID%>").val(result[1].p1);
$("#<%= TextBox5.ClientID%>").val(result[1].p2);
$("#<%= TextBox6.ClientID%>").val(result[1].p3);
},
error: function (status, ex) {
alert("Error Code: Status: " + status + " Ex: " + ex);
}
});
return false;
});
});
Default.aspx.vb
<System.Web.Services.WebMethod> _
Public Shared Function fn1(ByVal mo As Double, ByVal dy As Double, ByVal yr As Double) As String
Dim planetList As New List(Of planetClass)()
'...calculations....
Dim ca As New planetClass()
ca.p1 = Convert.ToDouble(a(1))
ca.p2 = Convert.ToDouble(a(2))
ca.p3 = Convert.ToDouble(a(3))
planetList.Add(ca)
Dim ce As New planetClass()
ce.p1 = Convert.ToDouble(ecc(1))
ce.p2 = Convert.ToDouble(ecc(2))
ce.p3 = Convert.ToDouble(ecc(3))
Dim serializer = New System.Web.Script.Serialization.JavaScriptSerializer()
fn1 = serializer.Serialize(planetList)
End Sub