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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:40:37+00:00 2026-05-27T19:40:37+00:00

Okay, what have I done wrong here? I’m trying to .POST data from a

  • 0

Okay, what have I done wrong here?
I’m trying to .POST data from a Form with JQuery $.ajax function and return json data. But every time the post data is null.

Here is the HTML/JQuery Part

<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/redmond/jquery-ui.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>
</head>

<body>
<form action="testform" method="post">
OLD ID:
<input id="OldID" name="OldID" type="text"><br>
NewID:
<input id="NewID" name="NewID" type="text"><br>

<input id="do" name="do" type="button" value="Get New ID">

</form>

<script type="text/javascript">

            var CID = $('#OldID').val();

        $(document).ready(function(){
                $('#do').click(function(){
                    sendValue();   
                }); 

        function sendValue(CID){

               $.ajax({
                  type: 'POST',
                  url: 'getNewID.php',
                  data: {OldID: CID},
                  dataType: 'json',
                  cache: false,
                  success:  
                    function(data){
                    $('#NewID').val(data.NewID);
                    }
              }) }
        });

</script>


</body>
</html>

Here’s the PHP page

<?php 

if (isset($_POST['OldID'])){

    $value = $_POST['OldID'];   

}else{
    $value = "ELSE VALUE";
}
echo json_encode(array("NewID"=>$value));  

?>

I’m sure this is a simple mistake on my part but I’m just going in circles at this point.

Thanks in advance!

  • 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-27T19:40:37+00:00Added an answer on May 27, 2026 at 7:40 pm

    Your mistake is that you are getting the value of the OldID field in your script, and not on some event handler method. This causes when the script is loaded (when the page is being viewed), the value of the text input is kept on variable CID. and when the user clicks on the #do button, then the value of CID is still the same as the one when the page was loaded. So no value is stored in CID variable, so no value is sent via AJAX.
    Define another function (Say sendOldID) that reads the value of the text input in the CID variable, and then calls the sendValue() method with CID paramter. The use that function as the event handler of the #do button clicked.

    <script type="text/javascript">
        $(document).ready(function(){
                $('#do').click(function(){
                    sendOldID();   
                });
    
        function sendOldID() {
            var CID = $('#OldID').val();
            sendValue(CID);
        }
    
        function sendValue(CID) {
               $.ajax({
                  type: 'POST',
                  url: 'getNewID.php',
                  data: {OldID: CID},
                  dataType: 'json',
                  cache: false,
                  success:  
                    function(data){
                    $('#NewID').val(data.NewID);
                    }
              }) }
        });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay i've seen this done somewhere before where you have a function that takes
Okay, I have done a bit of searching online and found this thread, but
Okay I have 2 files. One file is data that is updated every 10
Okay so here's the thing: I have a linq query which loads approx. 1000
Okay this is probably a rookie question, but I have never done GUI programming
Okay, well I am trying to learn how to develop mac apps. I have
Okay, believe me I have been sitting here for a long time staring at
Hye guys. Okay. I have done this coding. But it seems have error. Can
Okay, not sure what I'm doing here, other than it's not right. Trying to
okay so I have two projects one in which I have done all the

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.