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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:18:11+00:00 2026-05-23T14:18:11+00:00

How can i post some ajax data to the controller function and get it

  • 0

How can i post some ajax data to the controller function and get it back? For I want to post one integer to the function, and get another integer (total votes for the item which ID is posted), and on success i want to echo that vote count.
I dont know how can i post the “id” to the controller function. Please see my code:

//post this integet
the_id = $(this).attr('id'); 

        $.ajax({
            type: "POST",
            data: the_id,
            url: "http://localhost/test/index.php/data/count_votes",
            success: function(){
                //the controller function count_votes returns an integer.
                //echo that with the fade in here.

                }
            });
  • 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-23T14:18:11+00:00Added an answer on May 23, 2026 at 2:18 pm
     $.ajax({
                type: "POST",
                data: {data:the_id},
                url: "http://localhost/test/index.php/data/count_votes",
                success: function(data){
                   //data will contain the vote count echoed by the controller i.e.  
                     "yourVoteCount"
                  //then append the result where ever you want like
                  $("span#votes_number").html(data); //data will be containing the vote count which you have echoed from the controller
    
                    }
                });
    

    in the controller

    $data = $_POST['data'];  //$data will contain the_id
    //do some processing
    echo "yourVoteCount";
    

    Clarification

    i think you are confusing

    {data:the_id}
    

    with

    success:function(data){
    

    both the data are different for your own clarity sake you can modify it as

    success:function(vote_count){
    $(span#someId).html(vote_count);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can some one post an example of using syslog outputter for log4r, I am
I'm trying to send some data via JQuery ajax to a grails controller Here's
Symptom: Some users cannot successfully POST, most can successfully POST. When the error occurs,
I was wondering if anyone can post an example of how to get a
I have some JQuery AJAX POSTing data to my backend C# WebForm. It POSTs
I am trying to perform this AJAX post but for some reason I am
I am using an AJAX form post to send some form fields to the
For some reason one particular AJAX call of mine is getting a No parameterless
I create a simple MVC Controller action, that takes some json data - then
Users on my site can post news items. But right now, it's all honor

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.