By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,946 Members | 709 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,946 IT Pros & Developers. It's quick & easy.

Pass variable into PHP via JAax

P: 1
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include('header.php'); 
  3.         require_once('/homepages/9/d322999378/htdocs/spaincoastrealty/wordpress_en/wp-admin/includes/image.php');
  4.         require_once("/homepages/9/d322999378/htdocs/spaincoastrealty/wordpress_en/wp-load.php");
  5.         global $wpdb;
  6.         global $posts;
  7. ?> <form id = "test" method = "post"> <div> <div class="control-group"> <label class="control-label" for="selectError">Site</label> <div class="controls"> <select name="sitechooser" id="sitechooser"> <option value="Site1" selected>Site1</option> <option value="Site2">Site2</option> </select> </div> </div> </div> <input type = "text" id = "site_value" value = "some text"> </form> <script>
  8.         $(document).ready(function (e) {
  9.  
  10.                 $('#sitechooser').change(function () {
  11.                     var selected = $("#sitechooser option:selected").text();
  12.                     if (selected == "Site1") {
  13.  
  14.                         var id = $('#site_value').val();
  15.                         $.ajax({
  16.                                 url: 'try.php',
  17.                                 dataType: 'JSON',
  18.                                 data: {id: id},
  19.                                 success: function(data){
  20.                                     alert(data);
  21.                                     id = data.id;
  22.                                     $('#id').text(id);
  23.                             }
  24.                         });
  25.                     } 
  26.  
  27.                 });
  28.         });        
  29.         </script> <?php
  30.  
  31.         echo "id = ".$id;
  32.  
  33.         ?>
I want to get id value in php $id variable.

Is something wrong in my code? THanks
Nov 22 '14 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
$_GET["id"] .
Nov 22 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.