Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

jquery submit refresh page stop

$("#prospects_form").submit(function(e) {
    e.preventDefault(); // <==stop page refresh==>
});
Comment

how to submit form without page refresh using ajax

// 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 :: connecting to mongodb using mongoose 
Javascript :: TypeError: value.toLowerCase is not a function 
Javascript :: jquery find parent 
Javascript :: jqery slectt div in div 
Javascript :: javascript element edit value 
Javascript :: apache angular routing 
Javascript :: @editorjs/list window not defined 
Javascript :: convert array to json in js 
Javascript :: discord.js message on member add 
Javascript :: stop next script when ajaxcall 
Javascript :: why does hoisting does not work in function expressions 
Javascript :: document not intialized react js 
Javascript :: how to get the data attached with an element in javascript 
Javascript :: jquery nearest 
Javascript :: convert text to binary javascript 
Javascript :: js is prime 
Javascript :: javascript compare two arrays of objects get same elements 
Javascript :: javascript object to params string 
Javascript :: convert firebase timestamp to date js 
Javascript :: breaking from a labeled while loop js 
Javascript :: grepper valid base64 
Javascript :: how to understand if nodejs is out of memory 
Javascript :: remove parent tr jquery 
Javascript :: get text of selected option in select2 jquery 
Javascript :: check if base64 
Javascript :: Javascript noFill 
Javascript :: comment p5js 
Javascript :: enable input jquery 
Javascript :: truthy or falsy value javascript 
Javascript :: show console chrome mac 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =