Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Laravel ajax form submit

   $('#comment').on('submit', function(e) {
       e.preventDefault(); 
       var name = $('#name').val();
       var message = $('#message').val();
       var postid = $('#post_id').val();
       $.ajax({
           type: "POST",
           url: host+'/comment/add',
           data: {name:name, message:message, post_id:postid}
           success: function( msg ) {
               alert( msg );
           }
       });
   });
Comment

how to submit form using ajax laravel

// First add jquery
// <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>

$(document).ready(function() {
  $("#myForm").on('submit', (function(e) {
    e.preventDefault();
    $.ajax({
      url: $(this).attr('action'),
      type: "POST",
      data: new FormData(this),
      contentType: false,
      cache: false,
      processData: false,
      success: function(response) {
        $("#myForm").trigger("reset"); // this line is to reset form input fields
        alert('submitted');
      },
      error: function(e) {
      	alert('Failed to sumit');
      }
    });
  }));
});
//don't forget to add csrf token
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript get time ago with moment 
Javascript :: draw text in js 
Javascript :: jquery einbinden in js 
Javascript :: scroll to bottom of a div react 
Javascript :: loopback unique field 
Javascript :: regex for no whitespace at the beginning and end 
Javascript :: string contains in react 
Javascript :: JS node instal fs 
Javascript :: js compare lists 
Javascript :: how to print a number with commas as thousands separators in javascript 
Javascript :: how to get the end of an array javascript 
Javascript :: loopback model properties 
Javascript :: js cant find element 
Javascript :: vanilla javascript remove data attribute 
Javascript :: make page refresh on top in react js 
Javascript :: .sequelizerc File Setup 
Javascript :: jquery add html to end of div 
Javascript :: find the missing value in an integer array javascript 
Javascript :: gms2 object functions 
Javascript :: regex diferent of 
Javascript :: how to create a new react native project 
Javascript :: convert base64 to uint8array javascript 
Javascript :: v-for vue 
Javascript :: javascript copy an object without reference 
Javascript :: json_encode escape 
Javascript :: install aos in react 
Javascript :: jquery add td to tr dynamically 
Javascript :: standalone form inside reactive form 
Javascript :: get alert after using ajax 
Javascript :: javascript get bit 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =