springmvcform-to-json
v2.0.2
Published
Convert Spring-MVC form fields to JSON representation
Downloads
2
Readme
springmvcform-to-json
Convert Spring-MVC form fields to JSON representation
Webjar dependency
Maven
<dependency>
<groupId>org.webjars.npm</groupId>
<artifactId>springmvcform-to-json</artifactId>
<version>2.0.2</version>
</dependency>
Using this library with plain old JS
var form = document.querySelector('#myForm');
var formData = new FormData(form);
var xhr = new XMLHttpRequest();
xhr.open('POST', '/path/someController.do?action=anAction');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onload = function() {
if (xhr.status !== 200) {
showErrors("<ul><li>Oops something went wrong on our side.</li></ul>");
}
};
xhr.send(serializeFormData(formData));
Using this library with jQuery
$.ajax({
url: contextPath + '/path/someController.do?action=anAction',
data: serializeFormDataArray($('#myForm').serializeArray()),
method: 'POST',
dataType: 'json'
}).error(function() {
_showErrors("<ul><li>Oops something went wrong on our side.</li></ul>");
});
Building and Testing
npm run build
npm test