Skip to content

Instantly share code, notes, and snippets.

@morontt
Created September 4, 2014 10:16
Show Gist options
  • Select an option

  • Save morontt/c335bddffff3b0b3351e to your computer and use it in GitHub Desktop.

Select an option

Save morontt/c335bddffff3b0b3351e to your computer and use it in GitHub Desktop.
JavaScript file upload
$(function () {
$('#attachment-field').change(function () {
var file = this.files[0];
//image file only
if (file.type.match(/^image\//)) {
var request = new XMLHttpRequest();
request.open('POST', '/upload/path');
request.send(new FormData(document.getElementById('form-xyz')));
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment