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

140
Visualizações
execute ajax after enter and press button

i have easy ajax script, which send data from form, it work this button, and i want to date send when i press enter, how i can make it? Very thanks!

ajax code

jQuery(document).ready(function(){
    jQuery('.ajaxSubmit').click(function(e) {
        e.preventDefault();
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
            }
        });
            jQuery.ajax({
                url: "{{ url('/names') }}",
                method: 'get',
                data: {
                    runBy: $(this).closest("form").find(".name").val(),
                    command: $(this).closest("form").find(".surname").val(),
                },
                success: function() {
                    location.reload();
                }
            });
    });
});

php code

  <form>
       <input type="hidden" value="{{Auth::user()?->name}}" class="name">
        <textarea class="surname" name="input" cols="30" rows="1"> </textarea>
        <button class="ajaxSubmit" onclick="event.preventDefault()">send</button>
  </form>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Move your Ajax submission code to a separate function. Add the Keypress event to the input element. Call that function from the keypress event when the keypress value is 13. Below is the code for your reference.

$('.input').keypress(function (e) {
  if (e.which == 13) {
    // Call the callback function
    return false;
  }
});

call the same Ajax function from a button click.

Regards, omi

about 4 years ago · Juan Pablo Isaza 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