Created
December 4, 2015 13:45
-
-
Save wzulfikar/aff5642d4ef5022e2845 to your computer and use it in GitHub Desktop.
attaching image in summernote editor (ajax)
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
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not working on v0.8.9...