gpt4 book ai didi

javascript - jQuery 文件上传。无法读取 null 的属性 'innerHTML'

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:10:58 25 4
gpt4 key购买 nike

我正在尝试在我的项目中使用 blueimp 的 jQuery 文件上传插件。这在 Basic Plus 版本中完美运行,我能够在服务器上加载文件,但是当我尝试使用 Basic Plus UI ( link ) 时出现错误:

tmpl.min.js:1 Uncaught TypeError: Cannot read property 'innerHTML' of null
at Function.n.load (http://127.0.0.1:8000/static/cp/file_upload/tmpl.min.js:1:324)
at n (http://127.0.0.1:8000/static/cp/file_upload/tmpl.min.js:1:208)
at n (http://127.0.0.1:8000/static/cp/file_upload/tmpl.min.js:1:204)
at $.(anonymous function).(anonymous function)._initTemplates (http://127.0.0.1:8000/static/cp/file_upload/jquery.fileupload-ui.js:661:46)
at $.(anonymous function).(anonymous function)._initTemplates (http://127.0.0.1:8000/static/cp/file_upload/vendor/jquery.ui.widget.js:127:25)
at $.(anonymous function).(anonymous function)._initSpecialOptions (http://127.0.0.1:8000/static/cp/file_upload/jquery.fileupload-ui.js:681:18)
at $.(anonymous function).(anonymous function)._initSpecialOptions (http://127.0.0.1:8000/static/cp/file_upload/vendor/jquery.ui.widget.js:127:25)
at $.(anonymous function).(anonymous function)._create (http://127.0.0.1:8000/static/cp/file_upload/jquery.fileupload.js:1390:18)
at $.(anonymous function).(anonymous function)._create (http://127.0.0.1:8000/static/cp/file_upload/vendor/jquery.ui.widget.js:127:25)
at $.(anonymous function).(anonymous function)._super (http://127.0.0.1:8000/static/cp/file_upload/vendor/jquery.ui.widget.js:114:36)

这是我的项目中 js 需求的顺序:

vendor/jquery.ui.widget.js
JavaScript-Templates/js/tmpl.min.js
JavaScript-Load-Image/js/load-image.all.min.js
canvas-to-blob.min.js
jquery.iframe-transport.js
jquery.fileupload.js
jquery.fileupload-process.js
jquery.fileupload-image.js
jquery.fileupload-validate.js
jquery.fileupload-ui.js

实际上,即使我从示例中复制/粘贴源代码,我也会收到此错误消息。

编辑:

这里是html代码:

<input id="fileupload" type="file" name="files[]" class="form-control" multiple>
<div id="files" class="files"></div>

javascript(从 blueimp 示例复制):

$(function () {
'use strict';

// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload({
// Uncomment the following to send cross-domain cookies:
//xhrFields: {withCredentials: true},
url: '{% url 'add_request' %}',
});

// Enable iframe cross-domain access via redirect option:
$('#fileupload').fileupload(
'option',
'redirect',
window.location.href.replace(
/\/[^\/]*$/,
'/cors/result.html?%s'
)
);

if (window.location.hostname === 'blueimp.github.io') {
// Demo settings:
$('#fileupload').fileupload('option', {
url: '//jquery-file-upload.appspot.com/',
disableImageResize: /Android(?!.*Chrome)|Opera/
.test(window.navigator.userAgent),
maxFileSize: 999000,
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i
});
// Upload server status check for browsers with CORS support:
if ($.support.cors) {
$.ajax({
url: '//jquery-file-upload.appspot.com/',
type: 'HEAD'
}).fail(function () {
$('<div class="alert alert-danger"/>')
.text('Upload server currently unavailable - ' +
new Date())
.appendTo('#fileupload');
});
}
} else {
// Load existing files:
$('#fileupload').addClass('fileupload-processing');
$.ajax({
// Uncomment the following to send cross-domain cookies:
//xhrFields: {withCredentials: true},
url: $('#fileupload').fileupload('option', 'url'),
dataType: 'json',
context: $('#fileupload')[0]
}).always(function () {
$(this).removeClass('fileupload-processing');
}).done(function (result) {
$(this).fileupload('option', 'done')
.call(this, $.Event('done'), {result: result});
});
}

});

最佳答案

已解决。问题不在 javascript 中。我在模板中使用 django 标签。所以我不得不将 JavaScript-Templates 标签放入 {% verbatim %} django 标签中。谢谢大家。

关于javascript - jQuery 文件上传。无法读取 null 的属性 'innerHTML',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48019576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com