Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Submit forms via AJAX with ease

License

NotificationsYou must be signed in to change notification settings

github/remote-form

A function that will enable submitting forms over AJAX.

The function will make a request based on the form usingwindow.fetch with the payload encoded as URL parameters if the form method is aGET andFormData for all the other methods.

The request object is available in the callback function, allowing the headers and body to be modified before the request is sent.

Installation

$ npm install --save @github/remote-form

Usage

import{remoteForm}from'@github/remote-form'// Make all forms that have the `data-remote` attribute a remote form.remoteForm('form[data-remote]',asyncfunction(form,wants,request){// Before we start the requestform.classList.remove('has-error')form.classList.add('is-loading')letresponsetry{response=awaitwants.html()}catch(error){// If the request errored, we'll set the error state and return.form.classList.remove('is-loading')form.classList.add('has-error')return}// If the request succeeded we can do something with the results.form.classList.remove('is-loading')form.querySelector('.results').innerHTML=response.html})
<formaction="/signup"method="post"data-remote><labelfor="username">Username</label><inputid="username"type="text"><labelfor="password">Username</label><inputid="password"type="password"><buttontype="submit">Log in</button><divclass="results"></div></form>

Browser support

Browsers without nativecustom element support require apolyfill.

  • Chrome
  • Firefox
  • Safari
  • Microsoft Edge

Development

npm installnpm test

License

Distributed under the MIT license. See LICENSE for details.

About

Submit forms via AJAX with ease

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors11


[8]ページ先頭

©2009-2025 Movatter.jp