title: Show 2 responses for ajax success
body: <p>I am trying to display a message which checks for zipcode and returns whether cash on delivery and shipping is possible for zipcode entered.However I am able to get response for only one condition.Here I am posting the code which i am using.Can you help on how can i get to display message for COD and shipping differently.
  This is my phtml file.</p>
  
  <pre><code>&lt;script&gt;
          function checkPostcode() {
  
  
              var deliveryMessage = jQuery('#checkDelivery-form #is_deliverable');
              var deliveryMessage1 = jQuery('#checkDelivery-form #cod_delivery');
              deliveryMessage.removeClass('success').removeClass('error').hide();
              deliveryMessage1.removeClass('success').removeClass('error').hide();
              var deliveryForm = jQuery('#checkDelivery-form');
              if(deliveryForm.valid()) {
                  jQuery.ajax({
                      type: "POST",
                      url:'&lt;?php echo $this-&gt;getUrl('checkDelivery/postcode/check') ?&gt;',
                      data: deliveryForm.serialize(),
                      dataType: "json",
                      showLoader: true,
                      success: function(response) {
                          deliveryMessage.removeClass('mage-error');
                          deliveryMessage.removeClass('mage-success');
                          deliveryMessage.addClass(response.type).html(response.message).show();
                          deliveryMessage.attr('generated','true');
                      }
                      }
                  });
              }
              return false;
          }
  &lt;/script&gt;
  </code></pre>
  
  <p>Here is my php file checks for valid zipcode and displays response accordingy.</p>
  
  <pre><code>public function execute()
      {
          ob_start();
          $response = [];
          try {
              if (!$this-&gt;getRequest()-&gt;isAjax()) {
                  throw new \Exception('Invalid request.');
              }
              if (!$postcode = $this-&gt;getRequest()-&gt;getParam('zipcode')) {
                  throw new \Exception('Please enter pincode');
              }
  
              $region = $this-&gt;zipcodeRegion-&gt;getCollection()-&gt;addFieldToSelect('*')-&gt;addFieldToFilter('zip_code',$postcode)-&gt;getFirstItem();
  
              if($region['zip_code'] == $postcode)
              {
                  if($region['is_blocked'] == 1)
                  {
                      if($region['is_cod_available'] == 0)
                      {
                          $response['type'] = 'mage-error';
                          $response['message'] = 'No delivery available at selected pincode';
                      }
  
                  }
                  else
                  {
                      $response['type'] = 'mage-success';
                      $response['message'] = 'Delivery available at selected pincode';
                  }
              }
              else
              {
                  $response['type'] = 'mage-error';
                  $response['message'] = 'Please enter valid pincode';
              }
          } catch (\Exception $e) {
              $response['type'] = 'mage-error';
              $response['message'] = $e-&gt;getMessage();
  
          }
          $this-&gt;getResponse()-&gt;setContent(json_encode($response));
      }
  
  }
  </code></pre>