Skip to content

Instantly share code, notes, and snippets.

@hjblok
Last active March 14, 2017 00:50
Show Gist options
  • Save hjblok/5625761 to your computer and use it in GitHub Desktop.
Save hjblok/5625761 to your computer and use it in GitHub Desktop.
var formElement = document.getElementById("cart-form");
var formAction = "/cart";
var formMethod = "POST";
var formData = new FormData(formElement);
var file = load_your_file_here;
formData.append('properties[file]', file);
var xhr = new XMLHttpRequest();
xhr.open(formMethod, formAction);
//xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xhr.send(formData);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment