gpt4 book ai didi

javascript - div背景图片不改变重新上传

转载 作者:行者123 更新时间:2023-11-30 10:57:10 24 4
gpt4 key购买 nike

我有以下 HTML 页面。

enter image description here

<div class="profile-photo" id="profilephoto" style="background:url('data:image/png;base64,iVBORw0KGgoA') no-repeat 50% 50%;"></div>

使用 jQuery,我尝试替换这个 base 64 值,即 "iVBORw0KGgoA"

因此,在成功上传个人资料图片后,我尝试用新上传的图片替换此预览。这适用于第一次上传,但从第二次开始,使用不同的图像重新上传不会替换此图像预览。

使用以下 ajax 调用,我采用新的 base 64 值并在其成功调用中替换它:

    $.ajax({
type: "GET",
url: '@Url.Action("GetProfilePictureValue", "Student")',
data: { "StudentId": studentID },
dataType: "json",
success: function (newProfilePictureBase64Value)
{
$("#profilephoto").css('background', 'none');
$('#profilephoto').css('background', 'url(data:image/png;base64,' + newProfilePictureBase64Value + ') no-repeat 50% 50%;');
$("#profilephoto").load(location.href + " #profilephoto>*", "");

},
error: function ()
{
alert('Error occured');
}
});

最佳答案

您尝试清除浏览器的缓存吗?

关于javascript - div背景图片不改变重新上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59541572/

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