Skip to content

Instantly share code, notes, and snippets.

@wzulfikar
Created December 4, 2015 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wzulfikar/aff5642d4ef5022e2845 to your computer and use it in GitHub Desktop.
Save wzulfikar/aff5642d4ef5022e2845 to your computer and use it in GitHub Desktop.
attaching image in summernote editor (ajax)
<script>
/**
* Super simple WYSIWYG editor using Bootstrap.
* https://github.com/summernote/summernote
*/
$(document).ready(function() {
// init summernote with height: 200px
$('.summernote').summernote({
height: 200,
// tell summernote what to do on image upload
onImageUpload: function(files) {
// init form data and `append` whatever we need to send along.
// see: https://developer.mozilla.org/en/docs/Web/API/FormData
var data = new FormData();
data.append("file", files[0]);
$.ajax({
data: data,
type: "POST",
url: 'process-upload.php', // url to process this ajax request
cache: false,
contentType: false,
processData: false,
success: function(url) {
// the server should give the url of the file we uploaded
// so that we can tell summernote to insert that url to the editor.
$('.summernote').summernote('editor.insertImage', url);
}
});
}
});
});
</script>
@k2an
Copy link

k2an commented Apr 17, 2018

not working on v0.8.9...

@rupeshkumarseth
Copy link

where is process-upload.php

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