Miss any of our Open RFC calls?Watch the recordings here! »

springmvcform-to-json

2.0.2 • Public • Published

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

Install

npm i springmvcform-to-json

DownloadsWeekly Downloads

1

Version

2.0.2

License

ISC

Unpacked Size

8.81 kB

Total Files

5

Last publish

Collaborators

  • avatar