springmvcform-to-json
TypeScript icon, indicating that this package has built-in type declarations

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

Readme

Keywords

Package Sidebar

Install

npm i springmvcform-to-json

Weekly Downloads

0

Version

2.0.2

License

ISC

Unpacked Size

8.81 kB

Total Files

5

Last publish

Collaborators

  • donnchadh