You ca use JS using th:inline
like this, explanation is on comment
JS code
<script th:inline="javascript">
//Declare the URL of RequestMapping to use
//Do no change format
/*[+
var urlToload = [[@{/path/spring}]];
var anotherUrlToUse = [[@{/another/url?param=}]];
+]*/
//Handle you jquery event
$('body').on('click', '.dropdown-menu', function (e) {
var t = $(this);
//Sending your ajax request
$.ajax({
url: urlToload,
method: 'POST',
data: {
optionSelected: t.val()
}
})
/**
* Execute when your request is done
* @param {type} data : the page result of your Request *
*/
.done(function (data) {
$("#receiver").html(data);
})
//Execute on fail
.fail(function (xhr, ajaxOptions, thrownError) {
console.log("ERROR");
//Use anotherUrlToUse with GET METHOD to redirect
window.location.replace(anotherUrlToUse+404);
});
});
</script>
Controller code
@RequestMapping(value = "/path/spring", method = RequestMethod.POST)
public String controllerMethod(Model model, @RequestParam("optionSelected") String optionSelected) {
/**
* Do your job
* Your code
*/
return "page/result";
}