简体   繁体   English

跟踪并限制每个用户ajax网站列表项的点击次数

[英]Track and limit number of clicks on list item for website per user ajax

I have a list, each of whose item has a button, clicking on which open a dialog to show some information about that perticular item. 我有一个列表,每个列表项都有一个按钮,单击该列表会打开一个对话框,以显示有关该垂直项的一些信息。 Now I want to track how many distinct items are clicked by a logged in user. 现在,我想跟踪一个登录用户单击了多少个不同的项目。 If the number of item unlocked/clicked are greater than a number I should show some other dialog. 如果解锁/单击的项目数大于一个数字,我应该显示其他对话框。

I was trying to do it with javascript store API. 我试图用javascript 商店 API做到这一点。 But facing the issue of attaching the count to user and then binding it to user account. 但是面临将计数附加到用户然后将其绑定到用户帐户的问题。

This is what i was doing 这就是我在做什么

function showMobile(content, phone) {
// store.set('viewed_applied',0);
console.log(store.get('viewed_applied'));
if (store.get('viewed_applied') < 5) {
    $('#modal_body').html(content);
    $('#some_modal').modal('show');
    if (phone !== store.get("phone")) {
        var prev_viewed = store.get('viewed_applied');
        store.set('viewed_applied', prev_viewed + 1);
        store.set("phone", phone);
    }
} else {
    $('#planpricingModal').modal('show');
}

I am calling this function in each click of item button like this 我在像这样的项目按钮的每次单击中都调用此函数

 <div class="pull-right">
        <a class="btn btn-default-nohover" onclick="showMobile('sample_content','some_phone');">show content</a>
    </div

Is there any better way of achieving this using AJAX and backend? 是否有使用AJAX和后端实现此目的的更好方法? Please suggest. 请提出建议。

What you need is a database and a table for storing this kind of tracking information per user. 您需要一个数据库和一个表来存储每个用户的此类跟踪信息。 You can then use jQuery Ajax for updating or getting the tracking information. 然后,您可以使用jQuery Ajax来更新或获取跟踪信息。

You shouldnt simply showing one or another dialog. 您不应该简单地显示一个或另一个对话框。 Remember that half-smart user can check your source go get content of proper dialog. 请记住,半聪明的用户可以检查您的源代码以获得正确对话框的内容。 As answer above - every click in button should call ajax request to backend (for example php). 作为上述答案-每次单击按钮都应向后端调用ajax请求(例如php)。 Here you should recognize what content you should show to the user and that content should be returned from backend. 在这里,您应该认识到应该显示给用户的内容以及应该从后端返回的内容。 Recognizing how many times user already click the button is simple thanks to database for example (or another storage) 由于例如数据库(或其他存储),识别用户已经单击按钮的次数很简单

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM