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

138
Views
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 answers
Answer question

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 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!