title: AJAX shows different behaviors in an if/elseif-statement which is inside the success function
body: <p>I am new to web development and now I am using ajax for the payment section.</p>
  <p>Here is my ajax code.</p>
  <pre><code>$(document).ready(function (event) {
      $('#placeOrderForm').on('submit', function () {
          $.ajax({
              type: 'POST',
              url: '/user/checkout',
              data: $('#placeOrderForm').serialize(),
              success: function (data) {
                  console.log(data);
                  if (data.cod) {
                      alert(&quot;It's cod&quot;)
                  } else if (data.online) {
                      alert(&quot;It's online&quot;)
                  } else {
                      alert('Error in payment')
                  }
              }
          });
      });
  });
  </code></pre>
  <p>I am getting the alert properly when it enters the &quot;data.cod&quot; condition. But on the &quot;data.online&quot;  the alert is not working. But to my excitement the alert [It's online] appears  when I click the back button of the browser.</p>
  <p>I have tried with the following conditions(adding &quot;event.preventDefault()&quot;), but no results.</p>
  <p>First one,</p>
  <pre><code> $(document).ready(function (event) {
          event.preventDefault();
  </code></pre>
  <p>Second one,</p>
  <pre><code>  $(document).ready(function (event) {
          $('#placeOrderForm').on('submit', function () {
          event.preventDefault()
  </code></pre>
  <p>When I consoled the &quot;data&quot; in the success function it's also working fine.
  That is, for cod</p>
  <pre><code>{cod: true}
  </code></pre>
  <p>and for online,</p>
  <pre><code>amount: 840
  amount_due: 840
  amount_paid: 0
  attempts: 0
  created_at: 1660586301
  currency: &quot;INR&quot;
  entity: &quot;order&quot;
  id: &quot;order_K602IJ2FZLKSEa&quot;
  notes: []
  offer_id: null
  online: true
  receipt: &quot;62fa893d254dccabf61c899d&quot;
  status: &quot;created&quot;
  [[Prototype]]: Object
  </code></pre>
  <p>It will be great help if someone can resolve this issue.</p>