I'm attempting to make an ajax request to a very simple Grails method:
def countRace() {
Date date = params.date("date", 'yyyy-MM-dd');
Integer count = Race.countByDate(date);
log.info("Number of races on " + date + " is " + count);
return [count : count]
}
And I am using the following jQuery code to do it:
function updateDayRaceCount(id) {
$.ajax({
url: "${g.createLink(controller:'data', action:'countRace')}?date=" + id
}).done(function(response) {
alert(response);
});
}
I am seeing the logs fire on the server, so I know the method is being hit:
grails.app.controllers.runnerdb.DataController Number of races on Thu Mar 06 00:00:00 GMT 2014 is 38
But the ajax request is erroring out with a 404. When I observed the error, I found that it was the Tomcat standard 404 page, and the URL that was being generated, that looks like this:
/runnerdb/data/countRace?date=<id here>
Was being mapped to:
/runnerdb/WEB-INF/grails-app/views/data/countRace.jsp
This is where the issue is, because I imagine Tomcat or grails are trying to render a non-existent view.
My question is..
How to I stop this kind of behaviour in grails for just this one method, and force it to simply return the int value?