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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:24:53+00:00 2026-05-17T22:24:53+00:00

I have a simple AJAX function to send an id of an object to

  • 0

I have a simple AJAX function to send an id of an object to a php page

My function looks like this:

$(function(){      
    $("a.vote").click(function(){
        //get the id
        the_id = $(this).attr('id');
        alert(the_id);

        //ajax post
        $.ajax({
            type: "POST",
            data: "?id="+the_id,
            url: "vote.php",
            success: function(msg)
            {
                $("span#message"+the_id).html(msg);
            }
        });
    });
});

My vote.php looks like this:

session_start();
if(isset($_SESSION['user'])) {
    // db setup removed

    // insert vote into db
    $q = "UPDATE votes SET vote = vote + 1 WHERE id = " . $_POST['id'];   
mysql_query($q);      
echo "You sent " . $_POST['id'];
}

When I execute my AJAX function, it appears that the vote.php is never run

I know that my AJAX function is being called correctly, because alert(the_id); is popping up with the correct ID.

I know my vote.php is functioning correctly because I can run an HTML method=”post” with a textbox named “id”, and it will update the database correctly.

Can anyone see what’s wrong?

Thank you

  • 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-17T22:24:54+00:00Added an answer on May 17, 2026 at 10:24 pm

    You’re trying to send your variables in the URL, not as POST variables. Should be something like:

    $(function(){      
        $("a.vote").click(function(){
            //get the id
            var the_id = $(this).attr('id');
            alert(the_id);
    
            //ajax post
            $.ajax({
                type: "POST",
                data: {id:the_id},
                url: "vote.php",
                success: function(msg)
                {
                    $("span#message"+the_id).html(msg);
                }
            });
        });
    });
    

    Your data should be as included as an object, not as a string URL. Check out the examples on the jquery API page for more info on this!

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

Sidebar

Related Questions

I have a pretty simple AJAX and PHP code. While calling the PHP through
I got this example demonstrating AJAX from Stoyan Stefanovs Object Oriented JavaScript at page
I'm new to Ajax and this has me stumped. It's relatively simple but trips
I have simple JavaScript code that is using the Ajax API for fetching a
I have seen simple example Ajax source codes in many online tutorials. What I
I have some simple ajax code. All I want to do is load a
I am sending a json string using JQuery.ajax to a php page where I
I have created a Django app. I have a registration page(simple HTML form) in
I have a simple html page which renders with a number of nearly identical
I have simple link list and when you hover over it it appends a

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.