[英]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>
I have the above code which opens a modal box, a href inside slidera_img div makes a ajax get with following code. 我上面的代码打开了一个模式框,slidera_img div内的href使以下代码获得ajax。 After that I want to be able to update the div with slidera_num class to the current value i get from the ajax request. 之后,我希望能够将带有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);
});
}
I tried above but no luck. 我尝试以上但没有运气。
How can i do this? 我怎样才能做到这一点?
Thanks. 谢谢。
first just link to the image you need: 首先只需链接到您需要的图像:
<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>
then call fancybox to display it. 然后调用fancybox进行显示。 on that call you can hook with the onComplete
event that returns the item and then call any other ajax call you need to update the page. 在该调用上,您可以挂钩onComplete
事件,该事件返回该项目,然后调用您需要更新页面的任何其他ajax调用。 so just call it with: 因此只需调用:
$("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);
});
}});
Without knowing how fancybox works exactly, I can't help you much, but I can suggest some things: 不知道fancybox的工作原理如何,我无法为您提供很多帮助,但是我可以提出一些建议:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.