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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:20:41+00:00 2026-05-13T23:20:41+00:00

Playing with jquery for the first time, and I’m trying to get a simple

  • 0

Playing with jquery for the first time, and I’m trying to get a simple AJAX set up working so I can better understand how things work. Unfortunately, I don’t know a whole lot. Here’s the HTML with the script:

<html>
<head>
 <title>AJAX attempt with jQuery</title>
 <script type="text/javascript" src="jquery.js"></script>
 <script type="text/javascript">
   function ajax(str){
   $("document").ready(function(){
     $.post("ajaxjquerytest.php",str,function(){
       $("p").html(response);
       });
     });
 </script> 
</head>  
<body>
 <input type="text" onchange="ajax(this.value)"></input> 
 <p>Age?</p>
</body>
</html>

And here is the PHP it’s talking to:

<?php
$age = $_POST['age'];

if ($age < 30)
  {
  echo "Young";
  }
else if ($age > 30)
  {
  echo "Old";
  }
else
  {
  echo "you're 30";
  }
?>
  • 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-13T23:20:42+00:00Added an answer on May 13, 2026 at 11:20 pm

    Not sure if the $.post() function has access to the str parameter. Try this instead:

    <html>
    <head>
     <title>AJAX attempt with jQuery</title>
     <script type="text/javascript" src="jquery.js"></script>
     <script type="text/javascript">
        $("document").ready(function(){
            $('input').change(function() {
                 $.post("ajaxjquerytest.php",{'age': $(this).val()},function(response){
                     $("p").html(response);
                 });
            });
        });
     </script> 
    </head>  
    <body>
     <input type="text" />
     <p>Age?</p>
    </body>
    </html>
    

    This attaches an onChange handler to the input element after the DOM is completely loaded.

    Your approach should also work if you omit $(document).ready(). But attaching the JS function to the element is more the way it is done with jQuery.

    Besides that, you only need to wrap code into $(document).ready() that should be executed after the whole DOM tree is built. Your case, your are defining just a function. There is no need to use document ready as the function cannot be called until the DOM is loaded anyway.

    Read the documentation of .post()!

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

Sidebar

Related Questions

I've been playing with jquery and I've run myself into a time problem. I've
Recently I have started playing with jQuery, and have been following a couple of
I'm playing around with writing a jQuery plugin that uses an attribute to define
Just playing around with the now released Silverlight 2.0. I'm trying to put a
I have been playing with the Ruby library shoes. Basically you can write a
I am playing with Microsoft's TreeView control and I am trying to force a
Playing with log4net, I have seen the possibility to use a per-thread stack of
While playing around with regexps in Scala I wrote something like this: scala> val
I'm currently playing around with HTML_QuickForm for generating forms in PHP. It seems kind
I'm playing with ASP.NET MVC for the last few days and was able to

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.