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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:22:20+00:00 2026-05-26T01:22:20+00:00

I have looked for 2 days to find out how to send a variable

  • 0

I have looked for 2 days to find out how to send a variable with jquery to php. I have searched for over 100 posts on stackoverflow, i tried multiple examples. But i just get it done. So i really hope someone over here would be kind enough to help me find out what i am doing wrong….

<?php
print_r(json_decode($_POST['country']));
?>
<html>
<head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
    <script type="text/javascript">

        $(function() {
            $('#country').change(function() {

                var country = $('#country').val();

                $.ajax({
                    type: 'POST',
                    data: country,
                    dataType: 'json',
                    url: 'timezone/timezone.php',
                })

                alert("Country: " + country);

            });
        });

    </script>

</head>

<body>

    <form method = "post" name="form1">
        <select name="country" class="country" id="country">
            <option value="NL">Nederland</option>
            <option value="BE">Belgie</option>
        </select>
    </form>

</body>

</html>
  • 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-26T01:22:21+00:00Added an answer on May 26, 2026 at 1:22 am

    Data either needs to be a query string, or an object with a key and value.

    As an object

               $.ajax({
                    type: 'POST',
                    data: { 'country': country }
                    dataType: 'json',
                    url: 'timezone/timezone.php', 
                    success: function( data ) {
                       var element = data.wrap('<div />');  // wrap the response in a div 
                       $('body').append( element );   // append it to the body
                    }
                }); 
    

    as a query string

                $.ajax({
                    type: 'POST',
                    data: 'country='+country, 
                    dataType: 'json',
                    url: 'timezone/timezone.php'
                }); 
    

    Whenever in doubt always go to the jquery docs. Here is an excerpt from the ajax documentation.

    The data option can contain either a query string of the form key1=value1&key2=value2, or a map of the form {key1: ‘value1’, key2: ‘value2’}. If the latter form is used, the data is converted into a query string using jQuery.param() before it is sent. This processing can be circumvented by setting processData to false. The processing might be undesirable if you wish to send an XML object to the server; in this case, change the contentType option from application/x-www-form-urlencoded to a more appropriate MIME type.

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

Sidebar

Related Questions

I have looked and looked and tried to find an answer for what I've
I have looked over the Repository pattern and I recognized some ideas that I
I have looked and tried but don't see where I can stop some being
I've looked for days and I cannot find a solution to this problem. It's
I have spent three days trying to find the solution to this problem to
Have looked for a solution for 2 days now and am beating my head
Ok so i have looked everywhere and can not find anything. I know i
I've looked for days and to no avail. I can't find a function which
I have looked at the SQL Server 2008 feature comparison matrix and it lists
I have looked at NHibernate and EntitySpaces and they both seem to work differently.

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.