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 7552957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:55:04+00:00 2026-05-30T10:55:04+00:00

I have a similar to SO clone i am working on for practice. I

  • 0

I have a similar to SO clone i am working on for practice. I am in the middle of coding the vote system. I would like that when the upvote/downvote button is clicked, an Ajax call gets sent with the parameters for the processing page holding the post id and the value.

The post is needed to be able to know which post to record on the processing page that the javascript calls

I have a table of posts each with a post id and a votes table with votes with a vote id, so in my votes mapping table I record the topic id along side the post id.

However I cannot work out how to dynamically give a different post id for the Ajax call to each different post? Should I create perhaps a hidden field?

How is this generally done? Thanks a lot!

  • 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-30T10:55:05+00:00Added an answer on May 30, 2026 at 10:55 am

    On Stack Overflow, every post contains <input type="hidden" value="POSTID">. When a vote button is clicked, the code seeks for this input element, and sends an AJAX request, together with this post ID.

    You can have a look at the relevant code, here: http://userscripts.org/scripts/review/125051
    This user script allows all (including non-registered) users to view vote counts on posts. To do so, the post ID and vote buttons have to be located.

    Stripped down to the bare bones (excluding CSS), the code looks like:

    <input type="hidden" value="--post id--">
    <div class="vote upvote"></div>
    <div class="vote downvote"></div>
    
    // Example using jQuery:
    $('.upvote').click(function() {
        var $this = $(this);
        $.get('/vote', {
            postId: $this.siblings('input[type="hidden"]').val(),
            type: $this.hasClass('upvote') ? '+1' : '-1'
        }, function(data) {
            // do something with server's response.
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on several reports all of which have similar layouts I would
So I have 2 functions that both have similar arguments void example(int a, int
I know there are other questions that have similar issues, but I have read
I have 5 tables (tbl1, tbl2, tbl3, tbl4, tbl5) that all have similar columns,
I am maintaining several Perl scripts that all have similar code blocks for different
I have two very similar pieces of ASP.NET code that send a file in
I have this code that I've been working on and when I run it
I have a project that I'm currently working on but it currently only supports
I am working on a twitter clone in PHP for school, and I have
I have an HTML table, to which I would like to add or remove

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.