Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
jQuery Ajax POST save delete submit

Here is my code

<form method="post" role="form" id="form" enctype="multipart/form-data"  autocomplete="off">

<input type="submit" id="save" name="save" value="Simpan Data Client" class="btn" style="font-size:0.7em; letter-spacing:1px; color:#666666" /> //For save
<input type="submit" id="delete" name="delete" value="Delete Client" class="btn-delete" style="font-size:0.7em; letter-spacing:1px; color:#666666; padding:8px 15px" /> //For Delete
</form>
<script type="text/javascript">
$("#form").on("submit",function (e)
{
    e.preventDefault();
    var formData = new FormData($(this)[0]); 
    $.ajax(
    {
       url:'Master/Database/Client/RunClient.php',
       type: 'POST',
       data: formData,
       contentType: false,
       enctype: 'multipart/form-data',
       processData: false,
       beforeSend:function()
       {
        document.getElementById("loading").style.display = "";
       },
       complete:function()
       {
        //document.getElementById("loading").style.display = "none";
       },
       success:function(result)
       {
         document.getElementById("info").innerHTML = result;
         var n = result.search("error");
         if(n < 0) /*document.getElementById("form").reset();*/ $(".input").val('');

       }
    });
});
</script>

I can get all data from inside my form except from Input type submit i make. I can't use isset($_POST["save"]) and isset($_POST["delete"]) at my RunClient.php

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Create separate function for a submit and pass "submit type" depending on what button is clicked;

$('#save').click(function() {
  submitForm('save');
});
$('#delete').click(function() {
  submitForm('delete');
});
function submitForm(submittype) {
   var formData = new FormData(); 
   //push your form data to formData and add the submittype
   formData['type'] = submittype
}

in your php file

$submittype = $_POST['type']; // 'save' or 'delete'
if($submittype == 'save') {
 //do save action
}
if($submittype == 'delete') {
 //do delete action
}
about 4 years ago · Santiago Trujillo Report

0

I use to avoid submit inputs and change by buttons.

<button type="button" id="save">SUBMIT</button> //For save

<script type="text/javascript">
$("#save").on("click",function (e)
{

});
</script>

So, if anyone deativates javscript form will not submit.

And you can send the data like this:

data: {
    foo: 'var'
    foo2: 5
}, 

EDIT. Sorry missunderstood your question. Just control with javascript what button is clicked and assign a value with a hidden field.

about 4 years ago · Santiago Trujillo Report

0

'$("#form").on("submit",function (e)' replace the function with

$("#save").click(function() {

});

$("#delete").click(function() {

});

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!