동일한 페이지의 ajax에서 div로 데이터를 검색하려고하는데, ajax에서 데이터를 가져 오지 못했습니다. 내부 데이터를 가져 오려는 div 일 수 있지만, li 및 li의 자식입니다. ul에 대한 아이, 어떻게 해결할 수 있습니까?
여기에 HTML 코드가 있습니다.
<li>
<ul class="notificationsbtn nav navbar-nav navbar-right">
<li id="notificationsli">
<a id="test" name="@currentUser.Id" href="#" role="button" class="dropdown-toggle" data-toggle="dropdown">
<small><i class="glyphicon glyphicon-bell"></i></small>
@*@if (@Model.Where(n => n.IsRead == false).Any())*@
@*{*@<span class="noty-manager-bubble" style="margin-left:0px; top: 10px; opacity: 1;">@*@Model.Where(n => n.IsRead == false).Count()*@10</span>@*}*@
</a>
<div id="notification-container" class="dropdown-menu" role="menu" aria-labelledby="drop3">
<section class="panel">
<header class="panel-heading">
<strong>The Notification</strong>
</header>
<div id="notification-list">
@*@await Component.InvokeAsync("Notification")*@
<div style="float:left;margin-top:20px" class="loader"></div>
</div>
<footer class="panel-footer">
<a href="#" class="pull-right"><i class="fa fa-cog"></i></a>
<a asp-action="Index" asp-controller="Notifications" asp-route-id="@currentUser.Id" class="text-success h5" data-toggle="class:show animated fadeInRight"><span style="margin-left:0px; top: 5px; opacity: 1;" class="glyphicon glyphicon-bell"></span> all notifications</a>
</footer>
</section>
</div>
</li>
</ul>
</li>
및 jquery (ajax) 코드 :
<script>
$(document).ready(function () {
$('#test').click(function () {
{
alert("ssss");
//$("#notification-list").empty();
var _url = '@Url.Action("GetMyViewCompNotification", "Home")';
$(".loader").fadeIn();
$.ajax({
type: "GET",
url: _url,
data: { uid: $(this).prop("name") },
success: function (result) {
$("#notification-list").html(result);
alert("success")
},
error: function (xhr, status, err) {
alert(err.toString(), 'Error - LoadListItemsHelper');
},
complete: function (result, jqXHR, status) {
$(".loader").fadeOut();
}
});
}
});
});
</script>
컨트롤러의 액션 코드 :
public IActionResult GetMyViewCompNotification(string uid)
{
return ViewComponent("Notification", new { id = uid });//it will call Follower.cs InvokeAsync, and pass id to it.
}
문제가 발생했습니다. ajax 함수가 id ( "notification-list") 때문에 지정된 div에 데이터를 추가하지 않았습니다. ID를 ( "testn")으로 변경했을 때 데이터를 받았습니다.
<script>
$(document).ready(function () {
$('#test').click(function () {
{
//$("#notification-list").empty();
var _url = '@Url.Action("GetMyViewCompNotification", "Home")';
$(".loader").fadeIn();
$.ajax({
type: "GET",
url: _url,
data: { uid: $(this).prop("name") },
success: function (result) {
$(".testn").html(result);
},
error: function (xhr, status, err) {
alert(err.toString(), 'Error - LoadListItemsHelper');
},
complete: function (result, jqXHR, status) {
$(".loader").fadeOut();
}
});
}
});
});
</script>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다