Skip to content

Instantly share code, notes, and snippets.

@abr4xas
Last active August 6, 2019 14:57
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save abr4xas/22caf07326a81ecaaa195f97321da4ae to your computer and use it in GitHub Desktop.
Save abr4xas/22caf07326a81ecaaa195f97321da4ae to your computer and use it in GitHub Desktop.
Summernote image upload
$('.summer').summernote({
height: "200px",
callbacks: {
onImageUpload: function(files) {
url = $(this).data('upload'); //path is defined as data attribute for textarea
sendFile(files[0], url, $(this));
}
}
});
function sendFile(file, url, editor) {
var data = new FormData();
data.append("file", file);
var request = new XMLHttpRequest();
request.open('POST', url, true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
// Success!
var resp = request.responseText;
editor.summernote('insertImage', resp);
console.log(resp);
} else {
// We reached our target server, but it returned an error
var resp = request.responseText;
console.log(resp);
}
};
request.onerror = function(jqXHR, textStatus, errorThrown) {
// There was a connection error of some sort
console.log(jqXHR);
};
request.send(data);
}
@mylastore
Copy link

I get url of undefine

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