Z
Z
zelsky2015-07-31 02:02:10
JavaScript
zelsky, 2015-07-31 02:02:10

Sending request twice?

Why does it send twice?

[30/Jul/2015 23:00:17]"GET /send_like/?pk=36&user_id=3 HTTP/1.1" 200 1
[30/Jul/2015 23:00:17]"GET /send_like/?pk=36&user_id=3 HTTP/1.1" 200 1

$(document).on("click", ".likes", function (e) {
    e.preventDefault();
    var postid = $(this).data("postid");
    $.get('/send_like/',{"pk":postid,"user_id":userId}, function(e){
        $('.like_count[data-postid="'+postid+'"]').show();
        $('.likes[data-postid="'+postid+'"]').hide();
        $('.dislikes[data-postid="'+postid+'"]').hide();
    });
});

<span  class="likes" data-postid="{{one_post.pk}}" >
                                <i class="glyphicon glyphicon-thumbs-up"></i>
                            </span>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zelsky, 2015-07-31
@zelsky

Let's go. Twice registered the address to the script in base html

A
Alexander, 2015-07-31
@bIbI4k0

Most likely, the event fires a second time somewhere in the ancestors of the home node. Add event.stopPropagation() to your code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question