I've managed to successfully add AJAX into a Joomla module (see here for a highly imperfect implentation of how I did it Putting AJAX in a Joomla Module )
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.
JFactory::getApplication()->enqueueMessage('Some error message', 'error');
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.
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.
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!
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!