$('#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");
}
}
}
});
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>
$(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();
});
});