title: jQuery AJAX in a Joomla module
body: <p>I've managed to successfully add AJAX into a Joomla module (see here for a highly imperfect implentation of how I did it <a href="https://stackoverflow.com/questions/13446333/putting-ajax-in-a-joomla-module">Putting AJAX in a Joomla Module</a> )</p>
  
  <p>My problem I've got is returning errors in that when I'm throwing errors to date I've just been throwing a JApplication message e.g.</p>
  
  <pre><code>JFactory::getApplication()-&gt;enqueueMessage('Some error message', 'error');
  </code></pre>
  
  <p>However clearly this doesn't give the AJAX any sniff of an error so any time I submit it it calls it a 'success'. Hence my problem.</p>
  
  <p>Too many users for my liking still don't have Javascript enabled for me to feel happy to just add in a straight 400 header redirect (and in any case I would like the error message to be displayed to the user). I would still like the JApplication to just enqueue an error message through PHP as a fallback when javascript is disabled.</p>
  
  <p>I also saw methods of just echoing out the error message onto the page. But because of the not particularly useful way that Joomla modules deal with AJAX the call back data result is actually the full html code of the page! So I'd have to specifically select an element on the page I guess if I were to do it that way - and I'm not sure how to do that/if it's even possible!</p>
  
  <p>So what would be the best way of going about throwing an error message for the AJAX and then retrieve it so that I can display it to the User (yet still retain a nice non-javascript fallback?) Thanks!</p>