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

.ajax how to get data from form

$.ajax({
    ...
    data: $("#registerSubmit").serialize(),
    ...
})
Comment

ajax submit form data

<form id="contactForm1" action="/your_url" method="post">
    <!-- Form input fields here (do not forget your name attributes). -->
</form>

<script type="text/javascript">
    var frm = $('#contactForm1');

    frm.submit(function (e) {

        e.preventDefault();

        $.ajax({
            type: frm.attr('method'),
            url: frm.attr('action'),
            data: frm.serialize(),
            success: function (data) {
                console.log('Submission was successful.');
                console.log(data);
            },
            error: function (data) {
                console.log('An error occurred.');
                console.log(data);
            },
        });
    });
</script>
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

PREVIOUS NEXT
Code Example
Javascript :: p5.js boilerplate 
Javascript :: jquery change text of div 
Javascript :: js replace all char in string 
Javascript :: how to set height dynamically in jquery 
Javascript :: Clone an array using the JavaScript slice() method 
Javascript :: function click anywhere javascript 
Javascript :: jquery check if checkbox is not checked 
Javascript :: angular readonly if value is not null 
Javascript :: jquery checked 
Javascript :: fontawesome in next js 
Javascript :: javascript create div with class 
Javascript :: js object random key 
Javascript :: how to select data attribute in javascript 
Javascript :: javascript clone class prototype 
Javascript :: how to add print button on my website 
Javascript :: javascript on url anchor change event 
Javascript :: javascript determine array type 
Javascript :: add array to localstorage 
Javascript :: convert binary to decimal javascript 
Javascript :: jquery select radio by name 
Javascript :: npm could not determine node.js install directory 
Javascript :: day array in javascript 
Javascript :: createdAt 
Javascript :: how to detect the keyboard keys in js 
Javascript :: disable copy past jquery 
Javascript :: BROWSER=none npm start exited with code 1 
Javascript :: how to position View absolute react native 
Javascript :: fetch json 
Javascript :: batch md 
Javascript :: How to Check for a Null or Empty String in JavaScript 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =