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>

 

posted @ 2015-11-04 16:15  lijinbao  阅读(3576)  评论(0编辑  收藏  举报