jQuery 스크립트가 있는데, 해당 레코드를 삭제 한 후에 div를 숨길 것입니다. 다음은 jQuery입니다.jQuery Ajax 성공시 div 숨기기가 제대로 작동하지 않습니다.
$(document).ready(function() {
$(".deleteComment").click(function()
{
alert("asd");
var Id = $(this).attr("id");
var url1 = "@Html.Raw(Url.Action("DeleteComment", "Comment", new { id = "idValue" }))";
url1=url1.replace("idValue",Id);
alert(url1);
$.ajax(
{
type: 'post',
url: '/Comment/DeleteComment',
dataType: 'json',
data:
{
'EId' : Id
},
success: function (data)
{
alert ("Hello");
var commentBlock = $(this).closest('div');
commentBlock.hide('slow');
}
});
문제는 아래 코드에 : 나는 스크립트의 시작 부분에 위의 코드를 배치하면
success: function (data)
{
alert ("Hello");
var commentBlock = $(this).closest('div');
commentBlock.hide('slow');
}
다음 그것을 잘 작동합니다. 성공하면 성공하지 못합니다.
오류가 있습니까? – MikkoP
No..It 그냥 일하지 ... 그 코드는 내가 처음부터 그때 그것은 완벽하게 workd에 배치 ... – user1668543
"이"성공 콜백에서 "아약스 개체를 처리합니다. 따라서 "var self = this;"와 같은 선언을 한 다음 ajax 호출에서 $ (self) .closest 등을 사용해야합니다. –