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

143
Views
Using AJAX to display a message on page after HTTP POST request

On form submission I would like to stay on the same page and display a message (either success or failure). The HTTP POST request is handled as follows:

app.post('/insertdb', function(request, response) {
   // insert values from form into database
   response.json({success: true});
});

In the client side .ejs file I then try to use ajax to display the alert (I tried following the example from how to use NodeJS pop up a alert window in browser) as follows:

    <script>
      $.ajax({
        url: "/dbinsert",
        type: "post",
        data: 'testing',
        cache: false,
        success: function(response) {
          if(data['success']) {
            alert("success");
          }
          
        },
        error: function () {
          alert("There has been an error");
        }
      });
    </script>

The issue is that when I press the submit button it takes me off the page and displays: ```{"success":true}`` instead of staying on the same page after the form submission and displaying a popup with the status of the request.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

see here: Prevent redirect after form is submitted

you need to add return false; to the end of your AJAX request :)

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!