ajax not work when click open in new window after right click in django template

Viewed 20

i created a link with ajax this is a html coded:

<a id="post_click"  href="{{ post.online_url}}" rel="nofollow">
 <button class="w-100 "  type="button" name="button">
    <span class="">link</span>
</button>
</a>

and this is ajax :

$(function () {
$('#post_click').on('click', function () {
    var Status = $(this).val();
    var id = {{post.id}}
    $.ajax({
        url: "/post-click/" + id,
        data: {
       
        },
        dataType : 'json'
    });
});

});

if i push left click ajax work fine in sever side, but when i push left right click and choose open in new window ajax doesnt work

1 Answers

you have to set the good url in href for doing that :

<a id="post_click" href="/post-click/{{post.id}}" rel="nofollow">
 link
</a>
Related