weixin_33739523 2017-04-18 15:30 采纳率: 0%
浏览 3

像柜台

I want to create 'like' counter.

Currently I use ajax with php and on button click in like.php I update count in database and echo back count number to jquery.

$('btn').on('click',function(){

    $.ajax({
        url: 'like.php',
        type: 'post',
        data: someData,
        dataType: 'json',
    }).done(function(response){

        //increase like shown on response

    }).fail(function(jqXHR, textStatus, errorThrown) {

    }); 

 }); 

This would be triggering likes from client side.


I would like to do this on server side instead, so on button click to call php file:

Example (I put this in my page):

<a href="like.php?id=45">like</a>

And then in like.php update count in database as above.

2 questions:

  1. is it possible for url not to change when I click this?

  2. how would I echo back like count from like.php this way? (because I dont use ajax to call like.php like in first example)

  • 写回答

1条回答 默认 最新

  • weixin_33724659 2017-04-18 15:47
    关注

    to your first question: simply no! But you could make it a submit button and do post to the same url wich wouldn't change the url and you can push data through submit...

    to your second question -> your like.php has to return the whole html with your counter-value ;)

    cheerio :)

    评论

报告相同问题?