Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7416841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:34:43+00:00 2026-05-29T07:34:43+00:00

I have got a website where people can share activities just like Twitter, users

  • 0

I have got a website where people can share activities just like Twitter, users can Like them and Comment them.

Basically there is a filter that filters the list on date, so for example, show me all activities from today, what will happen is we make a request to our ajax controller, and it will send me the json for each activity based on the filter criteria, I got that all working.

How it works now is, when you press a filter criteria for example “today activities” we call the javascript method LoadActivities(filter); and it will just call the json, parse it and display all activities, now the question is what would be the best way to handle Likes and Comments, how I got it in mind was:

Each like button has the id “ActivityLike_{ACTIVITY_ID}” then make a click event, and split by ‘_’ and voila got the id of the activity, but once the user pressed the like button, it needs to re-render a single activity on the page, because “like” has to change to “not like anymore” etc. Same with commenting.

So how do I build this list, not using splits ‘_’ and other nasty solutions, but how can I do this in a proper clean way? Same question with jQuery “live” events, are they good to use or is there a work around?

Thanks for reading.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:34:44+00:00Added an answer on May 29, 2026 at 7:34 am

    Firstly it seems you’re building an application which is heavily reliant on JavaScript, and does very little in terms on progressive enhancement. If this is a well thought out decision, then cool.

    One thing I would recommend is to make use of data-* attributes rather than fiddling around with splitting the ID. Instead of ActivityLike_ID have a class of ActivityLike, and give each of those elements a data-id attribute of the Id. You then have;

    $(document).on('click', '.ActivityLike', function () {
        var theId = $(this).data('id');
    });
    

    Awesome.

    Because you’ve got simple cases of like <--> unlike and comment <--> remove comment this should be easy to do in JavaScript. You can add a class to the element when one of the states is selected, or can set a(nother) data attribute. A simple check in your code will let you know what to render the link as.

    If there’s a chance of more complicated manipulation occurring in future, you may be interested in letting the server control what to change in the page (as it’s likely the server has more context on the request than the client).

    Let the server return a data structure like this;

    [
        {
            "selector": "#something",
            "operator": "append",
            "params": ["<div>Hi</div>"]
        }
    ]
    

    I.e. an array of objects which map to jQuery operations. The selector describes the jQuery selector, the operator is the jQuery method to call and the params attribute is an array of parameters to pass the method.

    In the response handler for your AJAX request you can then do;

    for (var i=0;i<response.length;i++) {
        var curr = response[i];
    
        jQuery.fn[curr.operator].apply($(curr.selector), curr.params);
    }
    

    To handle those operations.

    As a concrete example, to give the HTML to unlike an activity, the server could respond with;

    [
        {
            "selector": ".like[data-id=\"activityId\"]",
            "operator": "html",
            "params": ["you liked this activity, click to unlike"]
        }
    ]
    

    Note that params must be an array (in this example it only has one element).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got IIS7 installed and have a simple website at: c:/inetpub/wwwroot/testsite I can copy
I have a website where people can upload 30+mb of data in a single
I've got different roles on my RPG website. Each user can have many roles
I got a link-sharing website hosted on linux, which allows users to share links.
I am developing a website and got a database where people can insert data
I have to submit subscription data to another website. I have got documentation on
Currently I have create a website using codeigniter. I got a message error every
I have two websites that post news information. I just got a request to
Have got an NSString *str = @12345.6789 and want to find out if there
We have got a custom MembershipProvider in ASP.NET . Now there are 2 possible

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.