【发布时间】:2019-06-04 08:10:07
【问题描述】:
我正在使用来自https://www.dropzonejs.com 的 dropzone 来上传单张图片。我正在使用 jquery 的命令 .load 加载一个 html 页面,如下所示:
$( "#showsettingsother" ).click(function() {
$('#settingscontent').load('settingscompany.html', function() {
Dropzone.autoDiscover = false;
var myDropzone = new Dropzone($('.dropzone').get(0), {
init: function() {
var me = this;
$.getJSON(webserverurl + '?sessionid=' + sessionkey + '&settings=true&company=checkCompanyPhotoExists', function( json ) {
if(json.STATUS == 'OK') {
var mockFile = { name: "Firmenlogo", dataURL: getcompanypicture, accepted: true };
me.createThumbnailFromUrl(mockFile, getcompanypicture);
me.files.push(mockFile);
me.emit('addedfile', mockFile);
me.emit('thumbnail', mockFile, getcompanypicture);
me.emit('complete', mockFile);
}
});
},
... [shortened]
}
}
}
在 settingscompany.html 里面我有这个:
<form id="uploadCompanyPicture" action="" class="dropzone"></form>
现在我有一个这样的菜单:
<ul>
<li id="settingscompany"><a id="showsettingscompany" href="#">Company settings</a></li>
<li id="othersettings"><a id="showsettingsother" href="#">Other settings</a></li>
</ul>
<script>
$( "#showsettingsother" ).click(function() {
$('#settingscontent').load('othersettings.html');
}
</script>
我的问题如下:
- 我将图片上传到 dropzone (image1.jpg)。这很好用。
- 我将第二张图片上传到 dropzone (image2.jpg)。这也很好用。
- 现在我点击“其他设置”,然后点击返回“公司设置”。
- 结果是,它显示的是 image1.jpg 而不是 image2.jpg。
- 当我重新启动浏览器时,它显示 image2.jpg。
所以它显示错误的图片。有人知道我做错了什么吗?
【问题讨论】:
-
getcompanypicture这个变量是存储新的还是旧的图片路径?
-
@Arthur Z.:getcompanypicture 是获取图片的 url 的变量。它总是一样的,是一个显示图片的 PHP 脚本。所以它肯定是新图片,因为当我关闭浏览器并重新加载页面时,它会显示正确的图片。
标签: javascript jquery xhtml dropzone.js dropzone