2017-09-13 35 views
0

当我通过ajax使用$this->image_lib->crop()调整图像大小或裁剪图像时,图像操作过程本身按预期工作。但是当我尝试使用$('#someDivId').css('background-image', 'url('+res.filepath+')');显示生成的图像时,显示的图像未被裁剪。是因为ajax同步还是什么?请帮忙..ajax未检测到图像作物

P.S.我使用jQuery版本1.12.4和笨3

Ajax调用我用看起来像这样:

$.ajax({ 
    url: '/mymodule/resize_img', 
    type: 'post', 
    data: $('form').serializeArray(), 
    dataType: 'json', 
    success: function(res) { 
    $('#someDivId').css('background-image', 'url('+res.filepath+')'); 
    }, 
    error: function(err) { 
    console.log(err.responseText); 
    } 
}); 
+0

我把它'res.filepath'指向正确(裁剪)的图像?您已通过在浏览器中直接打开它进行验证? –

+0

@JaromandaX是的,没错 – dapidmini

回答

0

我的朋友提出了一个解决方案,它的工作原理。

他怀疑图像是由服务器或浏览器缓存的。所以他告诉我使用一个额外的参数指的是这样的图像路径时:

改变了这一点:

$('#someDivId').css('background-image', 'url('+res.filepath+')');

成这样:

var n = Math.random(); 
var newImgPath = res.filepath + '?x=' + n; 
$('#someDivId').css('background-image', 'url('+newImgPath+')'); 

这种无聊又讨厌的事..