【发布时间】:2014-12-30 15:56:12
【问题描述】:
我有以下问题: 我想从后面的代码中调用 AktualisiereSilomethode,它应该返回一个字符串列表,但我得到的只是一个错误。 好像ajax方法没有调用后面的代码,但我不知道为什么。 我会很幸运能得到一些帮助。 如果您需要更多信息或更多代码,请写信给我。
我的代码: 1.ajax.js
//GET-Abfrage der Silos function GetSiloListe() { alert("In AJAX Aufruf"); $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "Karte.aspx/AktualisiereSilo", //data: "{}", (changed it) dataType: "json", success:function (data, textStatus, jQxhr) { alert("Success " + data); }, error: function (textStatus, errorThrown) { alert("Status: " + textStatus); alert("Error: " + errorThrown); }, }); }
- 我在 scripttag 中调用 karte.aspx
函数筒仓更新(){ GetSiloListe(); }
- 我的代码背后 (karte.aspx.vb)
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)>
Public Shared Function AktualisiereSilo() As String Dim siloModel As SiloModell = New SiloModell Dim siloList As List(Of SiloModell) = New List(Of SiloModell) Dim Datab As Database = New Database Dim list As String = "" Datab.InitializeDatabase() siloList = Datab.siloListQuery() For Each el In siloList list = list + el.longitude + "/" + el.latitude + ";" Next Return list End Function
【问题讨论】:
-
你需要为你的
AktualisiereSilo方法添加WebMethod属性,并制作static'. also you need to access the data in you success method usingdata.d`方法,因为asp.net将数据封装在变量d中
标签: jquery asp.net ajax json vb.net