To distinguish between normal requests and AJAX requests I check for
X-Request-With header that contains
To run this demo save it on your disk and run
perl ajax-demo.pl, default Mojolicious server will be started on
3000 port. So in your browser type
JQuery library is loaded via Google's content distribution network. So if don't have internet connection while testing the script, download JQuery (http://jquery.com/) yourself, put it into
public/ directory and change
script tag in demo template.
And here is the code. Having
render_json controller method in Mojolicious makes it easy to implement.