Last active
August 6, 2019 14:57
-
-
Save abr4xas/22caf07326a81ecaaa195f97321da4ae to your computer and use it in GitHub Desktop.
Summernote image upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I get url of undefine