我正在尝试通过用新文件覆盖现有图像文件来通过ajax更改用户图像,以便如何在不重新加载页面的情况下显示用户图像。
$(document).ready(function (e) {
$("#uploadimage").on('submit',(function(e) {
e.preventDefault();
// $("#message").empty();
// $('#loading').show();
alert('i m clicked');
$.ajax({
url: "ajax_php_file.php", // Url to which the request is send
type: "POST", // Type of request to be send, called as method
data: new FormData(this), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
contentType: false, // The content type used when sending data to the server.
cache: false, // To unable request pages to be cached
processData:false, // To send DOMDocument or non processed data file it is set to false
success: function(data) // A function to be called if request succeeds
{
// $('#loading').hide();
$('#previewing').hide();
// $("#message").html(data);
// $('PreviewImage').attr("src","<?php echo $ImageSource; ?>");
var img = $("#PreviewImage");
img.attr("src","<?php echo $ImageSource; ?>");
// alert(data);
}
});
}));
答案 0 :(得分:0)
根据@Deepak评论,我已将timestamp
与图片source
连接起来以显示新图片。
如果您的图片没有刷新,请在图片网址后添加时间字符串,例如
$timestamp = time(); img.attr("src","<?php echo $ImageSource.'?'.$timestamp;");