ajax - How to implement image upload to the PageDown markdown editor? -
to implement image upload pagedown markdown editor, have modified code editor.
markdown.editor.js
var defaultsstrings = { imagedialog : "< input id='image' type='file' />" }
when select picture , click ok button sent ajax request. can return image path.
var okbutton = doc.createelement("input"); okbutton.type = "button"; okbutton.onclick = function () { var data = new formdata(); data.append('file', $( '#image' )[0].files[0] ); $.ajax({ url: 'uploadfile', data: data, processdata: false, contenttype: false, type: 'post', success: function ( data ) { alert(path); } }); return close(false);};
how preview image in editor preview area?
this article provide useful method,
editor.hooks.set("insertimagedialog", function (callback) { var $input = $('<input type="file" name="file" id="file_0" class = "fileupload"/>'); var $okbutton = $('<a class="okbutton">'+uploadok()+'</a>'); $okbutton.click(function(){ var data = new formdata(); var file = $input[0].files[0]; if (file === undefined || null === file) { // alert("error message); } else { data.append('file', file); $.ajax({ url: 'uploadfile', data: data, datatype : 'json', processdata: false, contenttype: false, type: 'post', success: function ( data ) { callback(data.dataobject.url); }, error : function(data){ // error } }); } }); )
Comments
Post a Comment