<script type="text/javascript"> $(document).ready(function () { function sendFile(file, editor, $editable) { var formData = new FormData(); formData.append('file', file); // XMLHttpRequest 對象 var xhr = new XMLHttpRequest(); xhr.open("post", "/ajax/upload.aspx", true); xhr.onload = function () { alert("上傳完成!"); }; xhr.send(formData); //$.ajax({ // data: postdata, // type: "POST", // url: "/ajax/upload.aspx", //圖片上傳出來的url,返回的是圖片上傳后的路徑,http格式 // contentType: "json", // cache: false, // processData: false, // success: function (data) { // console.log(postdata); // //data是返回的hash,key之類的值,key是定義的文件名 // alert(data); // //把圖片放到編輯框中。editor.insertImage 是參數,寫死。后面的http是網上的圖片資源路徑。 // //網上很多就是這一步出錯。 // $('.summernote').summernote('editor.insertImage', "http://res.cloudinary.com/demo/image/upload/butterfly.jpg"); // $(".note-alarm").html("上傳成功,請等待加載"); // setTimeout(function () { $(".note-alarm").remove(); }, 3000); // }, // error: function () { // $(".note-alarm").html("上傳失敗"); // setTimeout(function () { $(".note-alarm").remove(); }, 3000); // } //}); } $('.summernote').summernote({ lang: "zh-CN", height: 200, tabsize: 2, onImageUpload: function (files, editor, $editable) { sendFile(files[0], editor, $editable); }, codemirror: { theme: 'monokai' } }); }); </script>