I am facing issue while displaying the result from a ajax call.
Contrller json method which returns data from database.
Элемент управления поступает в блок успеха моего вызова ajax, но данные пустые. если я отлаживаю метод GetNotifications контроллера, он возвращает данные. Может ли кто-нибудь помочь мне с этимJson результат не отображен
public JsonResult GetNotifications()
{
IList<Notification> notificationsBody = db.Notifications.ToList();
return Json(new { notificationsBody = notificationsBody }, JsonRequestBehavior.AllowGet);
}`View used to display and call ajax is
@model IEnumerable<NotificationApp.Model.Notification>
<h2>
Notification</h2>
@using (Html.BeginForm())
{
<ul id="nav">
<li id="notification_li"><span id="notification_count"></span><a href="#" id="notificationLink">
Notifications</a>
<div id="notificationContainer">
<div id="notificationTitle">
Notifications</div>
<div id="notificationsBody" class="notifications">
</div>
<div id="notificationFooter">
<a href="#">See All</a></div>
</div>
</li>
</ul>
}
@section Scripts {
<script src="~/Scripts/jquery-2.1.4.min.js" type="text/javascript"></script>
<script src="~/Scripts/jquery.signalR-1.1.4.js" type="text/javascript"></script>
<script src="~/signalr/hubs"></script>
<script type="text/javascript">
$(function() {
var proxy = $.connection.notificationHub;
proxy.client.receiveNotification = function (message, UnreadCount) {
$("#notification_count").html(UnreadCount);
$("#notification_count").show();
$("#container").slideDown(2000);
setTimeout('$("#container").slideUp(2000);', 5000);
};
$.connection.hub.start();
});
</script>
<script type="text/javascript">
$(document).ready(function() {
$("#notificationLink").click(function() {
$("#notificationContainer").fadeToggle(300);
$("#notification_count").fadeOut("slow");
var tbl = $('#notificationsBody');
$.ajax({
url: '/Notification/GetNotifications',
contentType: 'application/json ; charset:utf-8',
type: 'POST',
dataType: 'json'
}).success(function (result) {
alert(1);
alert(result[0].NotificationID);
tbl.empty().append(result);
}).error(function() {
alert(13);
});
//success: function (data) {
//if (data) {
//var len = data.length;
//var txt = "";
//if (len > 0) {
//for (var i = 0; i < len; i++) {
//if (data[i].Name && data[i].Address) {
//txt += "<tr><td>" + data[i].Name + "</td><td>" + data[i].Address + "</td></tr>"
// + "<td>" + data[i].PhoneNo + "</td>" + "<td>" + data[i].Country + "</td></tr>";
//}
//}
//if (txt != "") {
//$("#EmployeesTable").append(txt);
//alert(txt);
//}
//}
//}
//},
});
return false;
//Document Click hiding the popup
$(document).click(function() {
$("#notificationContainer").hide();
});
//Popup on click
$("#notificationContainer").click(function() {
return false;
});
});
</script>
}
`
здесь я получаю предупреждение, которое находится внутри блока успеха. Но строка alert (результат [0] .NotificationID); не отображает предупреждений.
Когда я пытаюсь опубликовать квестон, он дает предупреждение, что мой вопрос оставлен без ответа. Может кто-нибудь скажет мне, как его сортировать – Swathi
Мои вопросы остались без ответа. Я что-то пропустил, задавая вопрос. Может кто-нибудь подскажет мне, почему на вопросы здесь не отвечают? – Swathi