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:
- charset 
iso-8859-2 getinstead ofpostin both codes- commenting out 
scripttag includes 
script1.js:
- commenting out 
$(document).ready(function() {...lines - in 
data:tried changing quote symbols'"or no quote symbols @ all - 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'> </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
Post a Comment