title: How to send response to ajax post request in express node.js?[answered]
body: <p>I'm doing a simple project to practice node js along with Jquery Ajax.
  So I have an ajax post request that sends some data to nodejs server and wait for a response. In the server-side, I have a code that reads the data and do something with it. This works fine. But when I try to send the response back to ajax, the page changes and it shows the response in plain text. What I want is to do something with the response in ajax side.
  Sorry if I'm not clear, but hope you understand when reading the code.</p>
  
  <p>Jquery Ajax code:</p>
  
  <pre><code>$("submitBtn").on("click", e=&gt;{
          e.preventDefault();
          $.ajax({
              url: "/getCity",
              type: "POST",
              data: `city=${cityName}&amp;country=${countryName}`,
              success: function(data){
                  console.log(data);
              }
          });
      });
  </code></pre>
  
  <p>server-side code:</p>
  
  <pre><code>app.post("/getCity", (req, res)=&gt;{
      //a promise
      .then(cityID=&gt;{
          res.status(200).send(cityID.toString());
          });
  });
  </code></pre>
  
  <p>html code:</p>
  
  <pre><code>&lt;form method="post" action="/getCity"&gt;
      &lt;input/&gt;
      &lt;input/&gt;
      &lt;button id="submitBtn" type="submit"&gt;Search Weather&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I included html code because I don't know if putting <code>method="post" action="/getCity"</code> is necessary even though making the ajax post request.
  I hope you help me with this and if possible the html thing.
  Thank you in advance.
  NOTE: This question is a recreation of another question I asked before. I did it because it was marked as a duplicate, but after that it was answered by another user, only in a comment, who asked to do so in order to benefit others from it in the future.</p>