title: How I get ajax response from controller in magento 2
body: <p>I try to make an ajax call and pass the dropdown value in controller and get that particular related order information in view file. Response comes true but how to utilize that response in my view file.</p>
  
  <p><strong>Here is my phtml file</strong>:</p>
  
  <pre><code>&lt;select id="chartOption"&gt;
     &lt;option value=""&gt;Select Option&lt;/option&gt;
     &lt;option value="status"&gt;Status&lt;/option&gt;
     &lt;option value="payments"&gt;Payments&lt;/option&gt;
     &lt;option value="browser"&gt;Browser&lt;/option&gt;
  &lt;/select&gt;
  &lt;input type="button" name="chart_button" value="Generate chart" onclick="click_chart()"&gt;
  &lt;div id="result"&gt;&lt;/div&gt;
  &lt;script type="text/javascript"&gt;
          function click_chart() {
              var a = document.getElementById("chartOption");
              var abc = a.options[a.selectedIndex].value;
              data = jQuery(this).serialize();
              jQuery.ajax({
                  type: "POST",
                  dataType: "json",
                  contentType: "application/json",
                  url: "Blog/Post/Information", 
                  data: "label=" + abc,
                  success: function (result) { jQuery('#result').html(result); },
                  error: function (error) {  jQuery('#result').html(error); }
              });
          }
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>And here is my controller:</strong></p>
  
  <pre><code>public function execute() {
      if (isset($_REQUEST['ajax'])) {
          $label = $this-&gt;getRequest()-&gt;getPost('label');
          $_orders = $this-&gt;getOrders();
          $complete = $pending = $closed = $canceled = $processing = $onHold = 0;
          foreach ($_orders as $_order):
              $label = $_order-&gt;getStatusLabel();
              if ($label == 'Complete') {
                  $complete++;
              }
              if ($label == 'Pending') {
                  $pending++;
              }
              if ($label == 'Closed') {
                  $closed++;
              }
              if ($label == 'Canceled') {
                  $canceled++;
              }
              if ($label == 'Processing') {
                  $processing++;
              }
              if ($label == 'On Hold') {
                  $onHold++;
              }
          endforeach;
          $orderData = "['Task', 'Hours per Day'],['Complete'," . $complete . "],['Pending'," . $pending . "]],['Processing'," . $processing . "]],['Canceled'," . $canceled . "]";
          $arr = array('result' =&gt; $orderData);
          $jsonData = json_encode(array($arr));
          $this-&gt;getResponse()-&gt;setHeader('Content-type', 'application/json');
          $this-&gt;getResponse()-&gt;setBody($jsonData);
      }
  }
  </code></pre>