Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Ajax Form All Data Send

 $('#submit').on('click', function() {
             $.ajax({
                 url: "controller/php/add_project.php",
                 type: "POST",
                 data:  new FormData(document.getElementById("add_project_form")),
                 contentType: false,
                 processData:false,
                 cache: false,
                 success: function(dataResult){
                        console.log(dataResult);
                        var dataResult = JSON.parse(dataResult);
                        
                 },
                 error:function(dataResult){
                     console.log(dataResult);
                     alert('error / Add Project Again');
                 }
             });
         });
Comment

ajax call with form data

$.ajax({
    url: "jobs/php/job_single.php?type=500",
    type: "POST",
    data:  new FormData(document.getElementById("form")),
    contentType: false,
    processData:false,
    cache: false,
    success: function(dataResult){
      console.log(dataResult);
      if(dataResult == 999){
        alert("Incomplete Information Provided");
      }
      else{
        if(dataResult == 1){
        	alert("Job Application successful");
        	location.reload();
        }
        else if(dataResult == 0){
        	alert("Error applying for job, Please try again");
        }

      }
    }
}); 
Comment

Send Form Data Using Ky AJAX

async function(){
	const data = document.getElementById("myForm");
	
const fd =	new FormData(data);
let data = Object.fromEntries(fd);
 
const json = await ky.post('/test', {json: data}).json();

	console.log(json.x);
    
    
  ....
  <form id="myForm">
  <input name="value1" />
  </form>
Comment

Send forms with ajax

$(document).ready(function() {
  function SendFormWithAjax(id) {

    $.ajax({
      type: $(id).attr('method'),
      url: $(id).attr('action'),
      data: $(id).serialize(),

      success: function(data) {
        switch (data) {
          case 'success':
            $(id).trigger("reset"); //Reset form
            swal("Success",
                 "Nice",
                 "success");
            break;

          case 'warning':
            swal("Opps",
                 "Warning",
                 "warning");
            break;

          case 'error':
            swal("Error",
                 "Error",
                 "error");
            break;
        }
      }
    });
  }

  $('#form_one_id').on('submit', function(ev) {
    SendFormWithAjax(id);
    ev.preventDefault();
  });

  $('#form_two_id').on('submit', function(ev) {
    SendFormWithAjax(id);
    ev.preventDefault();
  });
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: convert jquery to string 
Javascript :: reload datatable without ajax 
Javascript :: create document mongoose 
Javascript :: react native meter 
Javascript :: moment format dd.mm.yyyy 
Javascript :: summation js 
Javascript :: javascript data structures 
Javascript :: sequelize update sql 
Javascript :: try catch in react native 
Javascript :: clean collection mongoose 
Javascript :: Validate email or phone number javascript 
Javascript :: truncate string in javascript 
Javascript :: update to node 12 mac 
Javascript :: body parser deprecated 
Javascript :: math.max in javascript 
Javascript :: loop over an array 
Javascript :: javascript get fibonacci number 
Javascript :: javascript check if number 
Javascript :: media queries generator script 
Javascript :: JavaScript for loop Display Sum of n Natural Numbers 
Javascript :: days in the current month 
Javascript :: js find integer 
Javascript :: jest wait for timeout 
Javascript :: upload file angular 
Javascript :: scroll load react 
Javascript :: multer express file upload 
Javascript :: toastandroid react native 
Javascript :: sveltekit tailwind 
Javascript :: index of an element 
Javascript :: js add multiple element to document 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =