[英]update div after ajax call
<li>
<div class="slidera_img">
<a href="image.jpg" rel="example_group" title="<a href='#' onClick='ajaxpost(@item.Id)'><img src='foo.jpg'/></a>">
<img src="@Url.Action("ViewImage", "Image", new { id = item.Id, imageType = "thumb" })" alt="" width="100" height="100" />
</a>
</div>
<div class="slidera_num">@item.VoteCount</div>
</li>
我上面的代码打开了一个模式框,slidera_img div内的href使以下代码获得ajax。 之后,我希望能够将带有slidera_num类的div更新为从ajax请求中获取的当前值。
<script type="text/javascript">
function ajaxpost(id) {
var item = $(this).parent();
alert(item);
$.get('@Url.Action("VoteAjax","Home")', { id: id }, function (response) {
item.closest("li").find(".slidera_num").html(response.vote);
});
}
我尝试以上但没有运气。
我怎样才能做到这一点?
谢谢。
首先只需链接到您需要的图像:
<a href="image.jpg" rel="example_group"><img src="@Url.Action("ViewImage", "Image", new { id = item.Id, imageType = "thumb" })" alt="" width="100" height="100" /></a>
然后调用fancybox进行显示。 在该调用上,您可以挂钩onComplete
事件,该事件返回该项目,然后调用您需要更新页面的任何其他ajax调用。 因此只需调用:
$("img[rel='example_group'").fancybox({ onComplete: function(item){
$.get('@Url.Action("VoteAjax","Home")', { id: item.id }, function (response) {
$(item).closest("li").find(".slidera_num").html(response.vote);
});
}});
不知道fancybox的工作原理如何,我无法为您提供很多帮助,但是我可以提出一些建议:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.