<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. 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.
<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. 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. 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:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.