Answers for "ajax php form data submit"

PHP
1

ajax php form submit

The form is submitting after the ajax request.

<html>
  <head>
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script>
      $(function () {

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

          e.preventDefault();

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

        });

      });
    </script>
  </head>
  <body>
    <form>
      <input name="time" value="00:00:00.00"><br>
      <input name="date" value="0000-00-00"><br>
      <input name="submit" type="submit" value="Submit">
    </form>
  </body>
</html>
Posted by: Guest on March-21-2021
1

formdata jquery ajax php

//set your ajax url here
//$url = 
$(document).on('submit', '#form',  function(e){
        e.preventDefault();
        $.ajax({
            type: 'POST',
            url: $url,
            data: new FormData(this),
            dataType: 'json',
            contentType: false,
            processData:false,//this is a must
            success: function(response){ 
                //statements on success
            }
        });
    });
Posted by: Guest on June-11-2021

Browse Popular Code Answers by Language