$('#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');
}
});
});
$.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");
}
}
}
});
var form = // Select your form here;
var fmData = new FormData();
form.append('name',fmData);
$.ajax({
url:'URL',
type:'POST',
data:fmData,
success:function(){},
error:(er){}
})
$.ajax({
...
data: $("#registerSubmit").serialize(),
...
})
<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>
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>