job.answiz.com
  • 1
Votes
name

Can anyone tell me why this bit of code isn't working?

<html>
  <head>
    [removed] src="http://code.jquery.com/jquery-1.9.1.js">[removed]
    [removed]
      $(function () {
        $('form').bind('submit', function () {
          $.ajax({
            type: 'post',
            url: 'post.php',
            data: $('form').serialize(),
            success: function () {
              alert('form was submitted');
            }
          });
          return false;
        });
      });
    [removed]
  </head>
  <body>
    <form>
      <input name="time" value="00:00:00.00">

      <input name="date" value="0000-00-00">

      <input name="submit" type="button" value="Submit">
    </form>
  </body>
</html>

When I push submit nothing happens. In the receiving php file I'm using $_POST['time'] and $_POST['date'] to put the data in a mysql query but it's just not getting the data. Any suggestions? I'm assuming it's something to do with the submit button but I can't figure it out

The form is submitting after the ajax request.

<html>
  <head>
    [removed][removed]
    [removed]
      $(function () {

        $('form').on('submit', function (e) {

          e.preventDefault();

          $.ajax({
            type: 'post',
            url: 'post.php',
            data: $('form').serialize(),
            success: function () {
              alert('form was submitted');
            }
          });

        });

      });
    [removed]
  </head>
  <body>
    <form>
      <input name="time" value="00:00:00.00">
<input name="date" value="0000-00-00">
<input name="submit" type="submit" value="Submit"> </form> </body> </html>
  • 1
Reply Report