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

  • Home
  • SEARCH
  • 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 6251181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:34:01+00:00 2026-05-24T13:34:01+00:00

I’m having a (probably super simple) issue. The code below is supposed to _POST

  • 0

I’m having a (probably super simple) issue. The code below is supposed to _POST (using AJAX) a variable called ‘id’ to an external file called getYourData.php.

I think the issue is below. The ‘data’ section doen’t seem to be functioning – I’ve even tried putting [data: ‘2’] to simply put ‘2’ in the SELECT statement. But that doesn’t even work.

$.ajax({
        type: 'POST',
        url: 'getYourData.php',
        data: 'id',
        success: function(msg){
            //everything echoed in your PHP-File will be in the 'msg' variable:
            $('#selectTwo').html(msg)
            $('#selectTwo').fadeIn(500);
        }
});

Here’s the rest of code (snippet – jquery has been imported)

<!-- First Box: click on link shows up second box -->
<div id="selectOne" style="float: left; margin-right: 10px; border: #666 thin solid; padding: 10px;">
  <a href="#" id="1">One</a><br />
  <a href="#" id="2">Two</a><br />
  <a href="#" id="3">Three</a>
</div>

<!-- Second Box: initially hidden with CSS "display: none;" -->
<div id="selectTwo" style="float: left; margin-right: 10px; display: none; border: #666 thin solid; padding: 10px;"></div>

<!-- The JavaScript (jQuery) -->
<script type="text/javascript">

//Do something when the DOM is ready:
$(document).ready(function() {

//When a link in div with id "selectOne" is clicked, do something:
$('#selectOne a').click(function() {
    //Fade in second box:
    $('#selectTwo').fadeIn(500);

    //Get id from clicked link:
    var id = $(this).attr('id');

    $.ajax({
        type: 'POST',
        url: 'getYourData.php',
        data: '2',
        success: function(msg){
            //everything echoed in your PHP-File will be in the 'msg' variable:
            $('#selectTwo').html(msg)
            $('#selectTwo').fadeIn(500);
        }
});

    //Depending on the id of the link, do something:
    if (id == 'one') {
        //Insert html into the second box which was faded in before:
        $('#selectTwo').html('One<br />is<br />selected')
    } else if (id == 'two') {
        $('#selectTwo').html('Two<br />is<br />selected')
    } else if (id == 'three') {
        $('#selectTwo').html('Three<br />is<br />selected')
    }

    });


});
</script>

getYourData.php – creates a custom SELECT statement based on the ‘id’ passed from primary page. For some reason, this isn’t working. Only works when I intentionally set a dud variable ($id2)

<?php


$username="primary";
$password="testpass";
$database="testdb";

mysql_connect(localhost,$username,$password) or die ('Unable to connect...');

mysql_select_db($database) or die('Error: '.mysql_error ());

//Intentionally creating a dud variable will create a good SELECT statement and work
$id2 = "3";

$id = $_POST['id'];
$query = mysql_query('SELECT * FROM members WHERE member_id='.$id);
$result = mysql_fetch_assoc($query);

//Now echo the results - they will be in the callback variable:
echo $result['firstname'].', '.$result['lastname'];

mysql_close();
?>
  • 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-24T13:34:02+00:00Added an answer on May 24, 2026 at 1:34 pm

    data in your AJAX function needs to be of the form ‘id=xxx’. I see you have it in the variable id. Try data: 'id=' + id. Confusing I know.

    The explanation here is that POST data should be of the form a=b,c=d,... et cetera. That way PHP will pick it up as a key/value pair in the $_POST dictionary. Now you have a variable id which you would like to send (value), and you also want this to be the name of the (key). Hence you would need to do data: 'id=' + id. If id=2, then that will evaluate to data: 'id=2', which is correct.

    Ultimately, as @Stephen noted, it is better to use an Object for the data field, as it is arguably more elegant. data: {'id': id} should work as well, and you can add more variables in the future.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.