zoukankan      html  css  js  c++  java
  • UEditor单个图片上传遇到的问题记录

     查看了ueditor.all.js得源代码发现单图片上传是在选择文件输入框change事件执行表单Submit,但是出现一个问题请求头没有加入Cookie,导致后端身份认证失败,上传最终失败。

    ueditor.all.js  24603行原代码:

              domUtils.on(iframe, 'load', callback);
                    form.action = utils.formatUrl(imageActionUrl + (imageActionUrl.indexOf('?') == -1 ? '?':'&') + params);
                    form.submit();

    后改为了jquery提交form表单,解决了问题,

      /*修改UEDITOR源码,form提交文件改为ajax上传*/
                    function ajaxUploadFile(url, form) {
                        $.ajax({
                            cache: true,
                            type: "POST",
                            url: url,
                            data: new FormData(form),// 你的formid
                            processData: false,
                            contentType: false,
                            error: function (request) {
                                
                            },
                            success: function (json) {
                                var link, json, loader,
                                    body = (iframe.contentDocument || iframe.contentWindow.document).body,
                                    result = body.innerText || body.textContent || '';
                                link = me.options.imageUrlPrefix + json.url;
                                if (json.state == 'SUCCESS' && json.url) {
                                    loader = me.document.getElementById(loadingId);
                                    loader.setAttribute('src', link);
                                    loader.setAttribute('_src', link);
                                    loader.setAttribute('title', json.title || '');
                                    loader.setAttribute('alt', json.original || '');
                                    loader.removeAttribute('id');
                                    domUtils.removeClasses(loader, 'loadingclass');
                                } else {
                                    showErrorLoader && showErrorLoader(json.state);
                                }
                                form.reset();
                            }
                        });
                    }
                    var action = utils.formatUrl(imageActionUrl + (imageActionUrl.indexOf('?') == -1 ? '?' : '&') + params);
                    ajaxUploadFile(action, form);
    
                    //domUtils.on(iframe, 'load', callback);
                    //form.action = utils.formatUrl(imageActionUrl + (imageActionUrl.indexOf('?') == -1 ? '?':'&') + params);
                    //form.submit();

    不知何故 原form submit 请求头未携带cookie,求解

  • 相关阅读:
    Docker学习总结(四)--应用部署
    strcat的由来
    ubuntu man不到pthread_mutex_XX
    string::front
    string::find_last_of
    string::find_last_not_of
    string::find_first_of
    string::find_first_not_of
    string::erase
    string::empty
  • 原文地址:https://www.cnblogs.com/tangchun/p/8796166.html
Copyright © 2011-2022 走看看