2017-08-30 120 views
-1

我有错误Django的summernote错误 “的成功是不是一个函数”

jquery.js:3860 jQuery.Deferred exception: imageInput.fileupload(...).success is not a function TypeError: imageInput.fileupload(...).success is not a function 
    at HTMLDivElement.onImageUpload (http://localhost:8000/test/:87:22) 
    at Context.triggerEvent (http://localhost:8000/static/django_summernote/summernote.min.js:3:13474) 
    at Editor.insertImagesOrCallback (http://localhost:8000/static/django_summernote/summernote.min.js:4:19085) 
    at Context.invoke (http://localhost:8000/static/django_summernote/summernote.min.js:3:14766) 
    at http://localhost:8000/static/django_summernote/summernote.min.js:5:23000 
    at mightThrow (http://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js:3583:29) 
    at process (http://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js:3651:12) undefined 

和 我的HTML头

<link href="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.css" rel="stylesheet"> 
    <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script> 
    <script src="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.js"></script> 
    <link href="/static/django_summernote/summernote.css" type="text/css" media="all" rel="stylesheet" /> 
    <link href="/static/django_summernote/django_summernote_inplace.css" type="text/css" media="all" rel="stylesheet" /> 
    <script type="text/javascript" src="/static/django_summernote/summernote.min.js"></script> 
    <script type="text/javascript" src="/static/django_summernote/jquery.ui.widget.js"></script> 
    <script type="text/javascript" src="/static/django_summernote/jquery.iframe-transport.js"></script> 
    <script type="text/javascript" src="/static/django_summernote/jquery.fileupload.js"></script> 
    <script type="text/javascript" src="/static/django_summernote/ResizeSensor.js"></script> 

,这是文件与成功相关功能

<script> 
$(function() { 
    var id_desc_textarea = window.document.getElementById('id_desc-textarea'); 
    var id_desc_src = window.document.getElementById('id_desc'); 
    var id_desc_settings = {"width": 720, "height": 480, "url": {"upload_attachment": "/summernote/upload_attachment/"}, "toolbar": [["style", ["style"]], ["font", ["bold", "italic", "underline", "superscript", "subscript", "strikethrough", "clear"]], ["fontname", ["fontname"]], ["fontsize", ["fontsize"]], ["color", ["color"]], ["para", ["ul", "ol", "paragraph"]], ["height", ["height"]], ["table", ["table"]], ["insert", ["link", "picture", "video", "hr"]], ["view", ["fullscreen", "codeview"]], ["help", ["help"]]], "lang": "en-US"}; 
    var csrftoken = getCookie('csrftoken'); 

    // include summernote language pack, synchronously 
    if(id_desc_settings.lang != 'en-US') { 
     $.ajaxSetup({async:false}); 
     $.getScript('/static/django_summernote/lang/summernote-' + id_desc_settings.lang + '.min.js'); 
     $.ajaxSetup({async:true}); 
    } 

    $(id_desc_textarea).hide(); 

    function recalcHeight(nEditor) { 
     var nToolbar = nEditor.find('.note-toolbar'); 
     var nStatusbar = nEditor.find('.note-statusbar'); 
     var nEditable = nEditor.find('.note-editable'); 
     var height = parseInt(
      parseInt(id_desc_settings.height) // default 
      - nToolbar.outerHeight() // toolbar height including margin,border,padding 
      - nStatusbar.outerHeight() // statusbar height including margin,border,padding 
     ); 
     nEditable.outerHeight(height); 
    } 

    $summernote = $(id_desc_src); 
    $summernote.summernote($.extend(id_desc_settings, { 
     callbacks: { 
      onInit: function() { 
       var nEditor = $('#id_desc').next(); 
       recalcHeight(nEditor); 

       // Resize again when the height of note-toolbar changed 
       // This enhances calculation behaviors on Safari 
       new ResizeSensor(nEditor.find('.note-toolbar'), function() { 
        recalcHeight(nEditor); 
       }); 
      }, 
      onBlur: function() { 
       id_desc_textarea.value = $(this).summernote('code'); 
      }, 

      onImageUpload: function(files) { 
       var imageInput = $('.note-image-input'); 
       var sn = $(this); 
       // custom attachment data 
       var attachmentData = id_desc_textarea.dataset; 
       imageInput.fileupload(); 
       var jqXHR = imageInput.fileupload('send', 
        { 
         files: files, 
         formData: $.extend({csrfmiddlewaretoken: csrftoken}, attachmentData), 
         url: id_desc_settings.url.upload_attachment, 
        }) 
        .success(function (data, textStatus, jqXHR) { 
         $.each(data.files, function (index, file) { 
          sn.summernote("insertImage", file.url); 
         }); 
        }) 
        .error(function (jqXHR, textStatus, errorThrown) { 
         // if the error message from the server has any text in it, show it 
         var msg = jqXHR.responseText; 
         if (msg.length > 0) { 
          alert('Got an error uploading an image: ' + msg); 
         } 
         // otherwise, show something generic 
         else { 
          alert('Got an error while uploading images.'); 
         } 
        }); 
      } 

     } 
    })); 

    // See https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax 
    function getCookie(name) { 
     var cookieValue = null; 
     if (document.cookie && document.cookie != '') { 
      var cookies = document.cookie.split(';'); 
      for (var i = 0; i < cookies.length; i++) { 
       var cookie = jQuery.trim(cookies[i]); 
       // Does this cookie string begin with the name we want? 
       if (cookie.substring(0, name.length + 1) == (name + '=')) { 
        cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); 
        break; 
       } 
      } 
     } 
     return cookieValue; 
    } 
}); 
</script> 

其他文件在https://github.com/summernote/django-summernote/tree/master/django_summernote/static/django_summernote

django版本是1.10 和django summernote版本是0.8.7.3

我该如何解决它?我想知道为什么它不起作用。 请回答我的问题。 我正在努力解决这个问题3天

+0

图片上传通过图片网址是好的,但通过本地文件得到错误 –

+0

请缩小问题多一点。通常你会注意到你的错误。 目前它太宽泛了,特别是因为SO不是一个调试服务。 – CWBudde

回答

0

我解决它通过更改jquery版本。谢谢!!!!!!!! 1

相关问题