Submit form laravel using AJAX and reset field
<form class="newsletter" id="newsletter">
   @csrf
   <input type="email" placeholder="Enter your email address" name="email" required="">
   <button type="submit">Subscribe</button>
</form>
<script>
      $('.newsletter').on('submit', function(e) {
         e.preventDefault(); 
         $.ajax({
            type: "POST",
            url: 'newsletter',
            data: $(this).serialize(),
            success: function(msg) {
               document.getElementById("newsletter").reset(); 
               swal("thank you for subscribing newsletter!");
            }
         });
      });
</script>

Leave a Comment