GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - roman01la/JSONFormData: HTML JSON form submission polyfill

This repository was archived by the owner on Aug 24, 2022. It is now read-only.
BranchesTags
Open more actions menu

Latest commit

 

History

32 Commits
32 Commits

Folders and files

NameName
Last commit message
Last commit date
examples
examples
 
 
src
src
 
 
test
test
 
 
.editorconfig
.editorconfig
 
 
.jshintrc
.jshintrc
 
 
.travis.yml
.travis.yml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
run-jasmine.js
run-jasmine.js
 
 

Repository files navigation

JSONFormData

HTML JSON form submission polyfill based on W3C HTML JSON form submission unofficial draft.

This is an early stage project.

Usage

There are two ways of using JSONFormData object, both similar to usual form submission process.

Raw HTML form

Once polyfill is included on a page, it's possible to submit a form asynchronously with minimum amount of JavaScript code.

<form enctype='application/json' action="/person" method="post">
    <input type="text" name="firstName">
    <input type="text" name="lastName">
    <button type="submit">Submit</button>
</form>
var form = document.querySelector('form');

new JSONFormData(form, (error, response) => {
    // Callback is called when response or error is received
});

HTML attributes

  • enctype application/json ― set request Content-Type header for JSON data.
  • action url ― request endpoint.
  • method GET POST PUT DELETE ― HTTP request method.

Both PUT and DELETE HTTP methods were removed in HTML5, but it makes sense to provide them for JSON form submission, which nicely fits CRUD approach.

JSONFormData object

Form data can be sent manually, similar to a way of sending FormData object. The data is stored in JSONFormData.formData.

form.addEventListener('submit', function (e) {

    const formData = new JSONFormData(form).formData;
    
    fetch("/api", {
      method: "POST",
      body: JSON.stringify(formData),
      headers: {
        "Content-Type": "application/json"
      }
    });
}, false);

About

HTML JSON form submission polyfill

Topics

form-datajson-form

Resources

Readme
MIT license
Activity

Stars

105 stars

Watchers

1 watching

Forks

15 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.