javascript - I can't pass a variable from my jQuery code to my PHP code -


i'm trying pass variable jquery code html/php code using ajax , post, error message "notice: undefined index: testdata in c:\xampp\htdocs\teszt\test1.php on line 9".

i'm using xampp, i'm running code in localhost, i'm using mozilla firefox , here's html/php code (test1.php):

<!doctype html> <html lang="hu">     <head>         <title>test</title>         <meta http-equiv="content-type" content="text/html;charset=utf-8">     </head>     <body>          <?php echo "<p class='testparagraph'>" . $_post['testdata'] . "</p>";?>          <script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>         <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>         <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.0.min.js"></script>         <script type="text/javascript" src="script.js"></script>     </body> </html> 

and here's jquery code (script1.js):

$(document).ready(function() {    var temporaryvariable = "temporary variable";     $.ajax({         type: "post",         url: "test1.php",         data: { testdata:"2" },         success: function (result) {             alert('success');         }       }).done(function() {         $('.testparagraph').addclass( temporaryvariable );         }); }); 

what tried changing far (but didn't work of course):

test1.php:

  1. charset iso-8859-2
  2. get instead of post in both codes
  3. commenting out script tag includes

script1.js:

  1. commenting out $(document).ready(function() {... lines
  2. in data: tried changing quote symbols ' " or no quote symbols @ all
  3. commenting out success: function... line , 2 lines below it

also, when run php code, p tag gets temporaryvariable class jquery code.

still, error message written above. appreciate get.

change test1.php to:

<!doctype html> <html lang="hu">     <head>         <title>test</title>         <meta http-equiv="content-type" content="text/html;charset=utf-8">     </head>     <body>          <p id='testparagraph'>&nbsp;</p> <!-- receive value jquery not php. -->          <script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>         <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>         <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.0.min.js"></script>         <script type="text/javascript" src="script.js"></script>     </body> </html> 

and script1.js to:

$(document).ready(function() {    var temporaryvariable = "temporary variable";     $.ajax({         type: "post",         url: "test1.php",         data: { testdata:"2" },         success: function (result) {             alert('success');         }       }).done(function() {         $('#testparagraph').html(temporaryvariable); //the value inserted paragraph.         }); }); 

hope works you.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -