Hello everyone, I am voting for the article, when I clicked on the link, I need to somehow transfer 2 parameters, this is + or - and the blog post id Please help, you need to transfer 2 parameters to the file post_vote.php I searched the Internet, read the docks, but how pass 2 parameters and I don’t understand how to specify them in the link

<a class="btn btn-small pull-right" href="#"><i class="icon-thumbs-down"></i></a> <a class="btn btn-small pull-right" href="#"><i class="icon-thumbs-up"></i></a> 

    2 answers 2

    1. Add a class to the pros and cons button buttonVote
    2. Add the data-id attribute, in the value of which we specify the record id. For example, data-id = "2"
    3. Add the data-vote attribute, in the value of which we specify where (+ (up) or - (down)): for example data-vote = "up"
    4. Handle the button

       $('.buttonVote').live('click', function(e) { e.preventDefault(); $.get('/script.php', {id: $(this).data('id'), vote: $(this).data('vote')}, function(data) { //Обрабатываем ответ }) }); 

    Instead of get, you can use post, of course)

    • Uncaught TypeError: Object [object Object] has no method 'live' error - Pavel Dura
    • then try instead of live, bind - iamsalnikov
    • Well, nothing happens at all, but what to write in the handler? - Pavel Dura
    • anything. This feature can be omitted. And you can even alert('голос учтен') that the console writes? Any errors? - iamsalnikov
    • one
     <a class="btn btn-small pull-right" href="post_vote.php?vote=up&post_id=1"><i class="icon-thumbs-down"></i></a> <a class="btn btn-small pull-right" href="post_vote.php?vote=down&post_id=1"><i class="icon-thumbs-up"></i></a> $(".btn").click(function(){ $.get($(this).href,function(data){ alert(data); }); return false; }); 

    data - what the post_vote.php script returns

    • does not work, only updates the ALL page and blog / post / 180 / post_vote.php? hits = url of the page ? vote = up & post_id = 1 - Pavel Dura
    • just a mistake in the code, it seems. I can be wrong $ (". Btn"). Live ("click", function () {$ .get ($ (this) .href, function (data) {alert (data);}); return false;}); - iamsalnikov
    • no, does not work Uncaught TypeError: Object [object Object] has no method 'live' - Pavel Dura
    • Straight is everyone using live() ... No one has moved to 1.9? - Indifferent
    • updated, try it - Yoharny Babai