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 :)

    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题