Posts data to a @ResourceMapping handler with Ajax.
var myURL = Liferay.PortletURL.createResourceURL();
myURL.setResourceId('handler-id');
myURL.setPortletId('myportlet_WAR_myportlet');
var myBean = {};
// namespace is necessary if <requires-namespaced-parameters>true</requires-namespaced-parameters>
myBean['_myportlet_WAR_myportlet_ragioneSociale'] = $('#myportlet_WAR_myportlet_ragioneSociale').val();
myBean['_myportlet_WAR_myportlet_email'] = $('#myportlet_WAR_myportlet_email').val();
myBean['_myportlet_WAR_myportlet_telefono'] = $('#myportlet_WAR_myportlet_telefono').val();
$.ajax({
type: 'POST',
dataType: 'json',
url: myURL.toString(),
data: myBean,
success: function (data, status, xhr) {
console.log('ok');
},
error: function () {
console.log('ko');
}
});
@ResourceMapping("handler-id")
public void resourceHandler(ResourceRequest request,
ResourceResponse response, @ModelAttribute MyBean Mybean) {
}