summernote 圖片上傳


    <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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM