Skip to content

Instantly share code, notes, and snippets.

@electerious
Last active February 15, 2021 02:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save electerious/67f23e511167629ffea9 to your computer and use it in GitHub Desktop.
Save electerious/67f23e511167629ffea9 to your computer and use it in GitHub Desktop.
const ajaxform = (form, next) => {
let url = form.action
let xhr = new XMLHttpRequest()
let data = new FormData(form)
xhr.open('POST', url)
xhr.onload = () => next(form, xhr)
xhr.send(data)
}
@electerious
Copy link
Author

Example:

let form = document.querySelector('form')

const next = function(form, xhr) {

    if (xhr.status===200 && xhr.responseText===true) {  }

}

ajaxform(form, next)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment