2.0.2 • Published 5 years ago

springmvcform-to-json v2.0.2

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

springmvcform-to-json

Build Status Code Coverage

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
2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago