javascript - Sending value from jquery to php not working -


i'm learning jquery , ajax. have tried following code, post value php jquery. doesn't work. can tell me mistake doing here, , solution.

i want value1 printed php server side code, value being sent jquery based client side code.

<html>  <head>     <title>practice 1</title>     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> </head>  <?php      if (isset($_post['data'])) {          $data = $_post['data'];          print( "data is: $data" );          return;      }  ?>   <body onload='process()'>     <script type="text/javascript">      $.post(window.location, {'data': "value1"}, function (data) {         $('#response').text(data);     });      </script>  </body>  </html> 

you're trying output element doesn't exist '#response', process function missing.

try this:

<html> <head>     <title>practice 1</title>     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">      </script> </head>  <?php      if (isset($_post['data'])) {          $data = $_post['data'];          print( "data is: $data" );          return;      }  ?>   <body> <div id="response"></div>     <script type="text/javascript">          $.post(window.location, {'data': "value1"}, function (data) {             $('#response').text(data);         });      </script>  </body> </html> 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -