ajax && serialize (ok)

ajax.php

<html>
  <head>
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script>
      $(function () {
        $('form').bind('click', function (event) {
        	event.preventDefault();
          $.ajax({
            type: 'POST',
            url: 'post.php',
            data: $('form').serialize(),
            success: function (data) {
              console.log(data);
            }
          });
        });
      });
    </script>
  </head>
  <body>
    <form>
      <input name="time" value="111111"><br>
      <input name="submit" type="submit" value="Submit">
    </form>
  </body>
</html>

post.php

<?php
if (isset($_POST["time"])) {
	echo '<pre>';
		print_r($_POST);
	echo '</pre>';
  $time = "";
  if (isset($_POST['time'])) {
  	$time = $_POST['time'];
  };
  echo $time;
}

Last updated