嗨,我尝试向我的 Web 服务发送参数以获取数据。但我总是得到一个错误:[对象错误]
那个错误是什么意思?
到目前为止,Web 服务正在运行。如果我在浏览器中调用 Web 方法,我会得到所有数据。
我做错了什么。我尝试了很多东西,但没有任何帮助..希望你能帮助我
我的查询:
function loadDate() {
jQuery.support.cors = true;
PanelID = document.getElementById('PanelID').value;
alert(PanelID);
jQuery.ajax({
type: "POST",
url: "http://nexxt-entwicklung.de/Web/Service1.asmx/getDatetime",
data: "{ 'PanelID': '" + PanelID + "' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert("Success: " + msg.d);
},
error: function(msg) {
alert("Failed: " + msg.status + ": " + msg.statusText);
}
});
}
我的网络服务:
[ScriptService]
public class Helper
{
public class VERANSTALTUNGEN
{
public string Von { get; set; }
public string Bis { get; set; }
public string Thema { get; set; }
public string PanelIDs { get; set; }
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static List<VERANSTALTUNGEN> getDatetime(string PanelID)
{
List<VERANSTALTUNGEN> Besprechungen = new List<VERANSTALTUNGEN>();
StringBuilder query = new StringBuilder("SELECT DISTINCT r.PanelID AS PANEL_ID, rr.Von AS DATEVON, rr.Bis AS DATEBIS, b.THEMA AS BESPRECHUNGSTHEMA FROM RAUM r right join RESERVIERUNGRAUM rr ON r.ID = rr.Raum_ID right join BUCHUNG b ON rr.BUCHUNG_ID = b.ID where r.PANELID = @ID ORDER BY rr.VON");
using (SqlConnection con = new SqlConnection(@"Data Source=Localhost\SQLEXPRESS;Initial Catalog=BOOK-IT_LH;Integrated Security=true;"))
using (SqlCommand cmd = new SqlCommand(query.ToString(), con))
{
cmd.Parameters.Add("@ID", System.Data.SqlDbType.Char);
cmd.Parameters["@ID"].Value = PanelID;
con.Open();
using (SqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
if (rdr["DATEVON"] != DBNull.Value && rdr["DATEBIS"] != DBNull.Value)
{
Besprechungen.Add(new VERANSTALTUNGEN()
{
Von = rdr["DATEVON"].ToString(),
Bis = rdr["DATEBIS"].ToString(),
Thema = rdr["BESPRECHUNGSTHEMA"].ToString(),
PanelIDs = rdr["PANEL_ID"].ToString()
});
}
}
}
}
return Besprechungen;
}
}
网络服务方法
[System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public List<Helper.VERANSTALTUNGEN> getDatetime(string PanelID)
{
return Helper.getDatetime(PanelID);
}
}