title: Joomla and AJAX
body: <p>I'm having a terrible time trying to get the ajax call below working in my Joomla 3.6 component. The javascript function below works in the sense that it does return the data and display it in the page--for a split second--then the page reloads, and I get the result of view.html.php, which is not what I need here. I get the same results whether I set the async property to true or false. It just happens much quicker with async set to true. The data returned in view.raw.php is fine. I must avoid reloading view.html.php. The javascript function getCase() is called by "onclick" of a button and I always clear the cache before testing.
  Thanks.</p>
  
  <pre><code>    function getCase(getDataVal) 
  {
      var examcaseid = ($('examcase_id')) ? $('examcase_id').value : -1;
      jQuery.ajax({
          type: 'GET',
          url: 'index.php?option=com_casecreator&amp;view=examcase&amp;format=raw&amp;layout=edit&amp;id='+examcaseid+'&amp;getdata='+getDataVal,
          dataType: 'html',
          contentType: 'text/html; charset=\"utf-8\"',
          async: true,
          success: function (data, status, jq) {
              $('rc_xml_display').innerHTML = data;
              //alert('In getCase(), rc_xml_display is: '+$('rc_xml_display').innerHTML);
          },
          error: function (jq, status, e) {
              alert('Unable to retrieve case.'+JSON.stringify(jq));
          }
      });
  
      return;
  }
  </code></pre>
  
  <p>Entire display() function from view.raw.php:</p>
  
  <pre><code>    public function display($tpl = null)
  {
      $app            = JFactory::getApplication();
      $getdata        = $app-&gt;input-&gt;get('getdata');
      $case_index     = !empty($app-&gt;getUserState('case_index')) ? $app-&gt;getUserState('case_index') : 0;
  
      if ($getdata == 'nextcase' || $getdata == 'previouscase' || $getdata == 'initialcase') {
          $app-&gt;setUserState('active_tab', 'browsecases');
          $cases_arr = $app-&gt;getUserState('rc_cases');
  
          switch ($getdata) {
              case 'nextcase':        $case_index++; break;
              case 'previouscase':    $case_index--; break;
              case 'initialcase':     $case_index = 0; break;
              case 'default':         break;
          }
          if ($case_index &lt; 0) {
              $case_index = 0; 
              $msg = 'You have reached the first case in the result set.';
              $app-&gt;enqueueMessage($msg, 'warning');
          }
          if ($case_index &gt;= count($cases_arr)) {
              $case_index = count($cases_arr)-1;
              $msg = 'You have reached the last case in the result set.';
              $app-&gt;enqueueMessage($msg, 'warning');
          }
  
          if ( !empty($cases_arr[$case_index]) ) {
              $app-&gt;setUserState('case_index', $case_index);
              $app-&gt;setUserState('current_case', $cases_arr[$case_index]);
          }
  
          header("Content-Type: text/html; charset=utf-8");
          print $app-&gt;getUserState('current_case');
          $app-&gt;close();
      }
  }
  </code></pre>