Ошибка Ajax webmethod C#
Привет, я пытаюсь создать динамические html-элементы на ajax success response, но сталкиваюсь с другой проблемой.
В консоли браузера я вижу результат успеха:
[{"ResponseTime":"13/6/2019 24:51","TicketId":0,"UserId":"ricky.global9@gmail.com","Subject":"Domain problem","Department":"Sales","Description":"Content 2","FileId":"NULL","ResponseType":null},{"ResponseTime":"13/6/2019 23:51","TicketId":0,"UserId":"ricky.global9@gmail.com","Subject":"_Payment_issue","Department":"Support","Description":"Content 1","FileId":"NULL","ResponseType":null}]{"d":null}
Здесь
{"d":null}подозрительный...
Но "Аякс" также вызывает функцию ошибка "не определено"
Вот мой Аякс
<pre> var tid = '2723021'; $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "../../Service.asmx/GetTicketDetails", data: "{ TicketID: '" + tid + "'}", dataType: "json", success: function (data) { var SignalTable = $('#ticketDetails'); SignalTable.empty(); $(data).each(function (index, sigs) { SignalTable.append('<p>' + sigs.ResponseTime + '</p><p>' + sigs.UserId + '</p><p> ' + sigs.Subject + '</p ><p>' + sigs.Department + '</p><p>' + sigs.Description + '</p><p>' + sigs.FileId + '</p><p>'); }); }, error: function (err) { alert('Err ' + err); } });
Веб-метод
<pre> public void GetTicketDetails(string TicketID) { List<SupportTicket> SideTickets = new List<SupportTicket>(); string CS = ConfigurationManager.ConnectionStrings["iqCon"].ConnectionString; using (SqlConnection con = new SqlConnection(CS)) { SqlCommand cmd = new SqlCommand("procSidebarTicketDetails", con); //Precedure query SELECT Response_time, User_email, Support_subject, Support_department, Support_description, File_id FROM Support_tickets WHERE Ticket_id = @Ticketid; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Ticketid", TicketID); con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { SupportTicket tickets = new SupportTicket(); tickets.ResponseTime = rdr["Response_time"].ToString(); tickets.UserId = rdr["User_email"].ToString(); tickets.Subject = rdr["Support_subject"].ToString(); tickets.Department = rdr["Support_department"].ToString(); tickets.Description = rdr["Support_description"].ToString(); tickets.FileId = rdr["File_id"].ToString(); SideTickets.Add(tickets); } } JavaScriptSerializer js = new JavaScriptSerializer(); Context.Response.Write(js.Serialize(SideTickets)); }
И объект класса
public class SupportTicket { public string ResponseTime { get; set; } public int TicketId { get; set; } public string UserId { get; set; } public string Subject { get; set; } public string Department { get; set; } public string Description { get; set; } public string FileId { get; set; } public string ResponseType { get; set; } }
Что я уже пробовал:
Я перепробовал все возможности со своей стороны, но не смог найти, где я делаю что-то не так.
Patrice T
И он говорит вам свое имя и положение ошибки ?
lmoelleb
And what does debugging show you? Incoming data on the backend as expected? Outgoing data? Where does the JavaScript encounter "nothing"? What did you expect this "nothing" to be? In case you think debugging is an advanced topic you will learn later, you are wrong. Debugging is simple and extremely useful. I can't think of a more important skill, no matter if you are just starting programming or have 30+ years experience. Learning to use a debugger takes 5-10 minutes. With both JavaScript and C# backend code, you need to learn VS and browser debugging. So then you might be looking at spending a whopping 10-15 minutes on a skill that will save you hours on even the smallest project.
F-ES Sitecore
Не используйте контекст.Пишите внутри веб-метода. Вот откуда берутся ваши данные "[{"ResponseTime"....", А "d:null" генерируется веб-методом. Google, как использовать инфраструктуры с помощью AJAX, есть множество примеров.