title: Using AJAX to display a message on page after HTTP POST request
body: <p>On form submission I would like to stay on the same page and display a message (either success or failure). The <code>HTTP POST</code> request is handled as follows:</p>
  <pre><code>app.post('/insertdb', function(request, response) {
     // insert values from form into database
     response.json({success: true});
  });
  </code></pre>
  <p>In the client side <code>.ejs</code> file I then try to use ajax to display the alert (I tried following the example from <a href="https://stackoverflow.com/questions/44915831/how-to-use-nodejs-pop-up-a-alert-window-in-browser">how to use NodeJS pop up a alert window in browser</a>) as follows:</p>
  <pre><code>    &lt;script&gt;
        $.ajax({
          url: &quot;/dbinsert&quot;,
          type: &quot;post&quot;,
          data: 'testing',
          cache: false,
          success: function(response) {
            if(data['success']) {
              alert(&quot;success&quot;);
            }
            
          },
          error: function () {
            alert(&quot;There has been an error&quot;);
          }
        });
      &lt;/script&gt;
  </code></pre>
  <p>The issue is that when I press the submit button it takes me off the page and displays: ```{&quot;success&quot;:true}`` instead of staying on the same page after the form submission and displaying a popup with the status of the request.</p>