[英]Ajax jQuery getting Error: [object Error]
Hi i try to send a parameter to my Webservice to get the Data. 嗨,我尝试将参数发送到我的Web服务以获取数据。 But iam getting always an Error: [object Error]
但是iam总是出现错误:[对象错误]
What does that Error means? 该错误是什么意思?
The Webservice is working so far. 到目前为止,Web服务正在运行。 If i Invoke the Webmethod in the Browser i get all the data.
如果我在浏览器中调用Web方法,则会获取所有数据。
What iam doing wrong. 我做错了什么。 I have tried many things, but nothing helped.. Hope you can help me
我尝试了很多事情,但是没有帮助。希望您能帮助我
My Query: 我的查询:
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);
}
});
}
My Webservice: 我的网络服务:
[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;
}
}
Webservice Method Web服务方法
[System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public List<Helper.VERANSTALTUNGEN> getDatetime(string PanelID)
{
return Helper.getDatetime(PanelID);
}
}
It means that msg.statusText
is an object that is an instance of Error
. 这意味着
msg.statusText
是作为Error
实例的对象。
Use console.log
instead of alert
to see what the object contains in a console in Chrome/Firebug, or loop through the object and alert each key/value. 使用
console.log
而不是alert
来查看对象在Chrome / Firebug的控制台中包含的内容,或遍历该对象并警告每个键/值。
When it comes to the problem itself, while using dataType json: 关于问题本身,使用dataType json时:
you shouldn't do: 你不应该这样做:
data: "{ 'PanelID': '" + PanelID + "' }",
but rather something like 而是类似
data: { 'PanelID': PanelID },
cause otherwise instead of posting some object you're sending string 否则导致您发送字符串而不是发布某些对象
do always make sure you read the specs: http://api.jquery.com/jQuery.ajax/ 请务必确保您已阅读规范: http : //api.jquery.com/jQuery.ajax/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.