Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

113
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

0

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

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

});

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

});

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda