有没有更好的方法来更新调用PHP页面的img标签?

时间:2011-09-14 14:35:06

标签: php jquery image jcrop

我正在使用jcrop,在用户crps图像后,我调用了一个返回img标签的php页面,如下所示:

$.get("get_profile_picture.php", function(data) {
    $('#profile_photo_id').html(data);

    jQuery('#cropbox').Jcrop({
        onChange: showPreview,
        onSelect: showPreview,
        aspectRatio: 1
    });        
});

$.get("get_profile_thumb.php", function(data) {
    $('#profile_thumb_id').html(data);
});

这很好但我担心的是每次用户上传新图像时我都会再拨两个电话。从get_profile_picture.php返回的img src代码如下所示:

<img src=<?php echo(getProfileThumb($user_id, FALSE)) ?> id="cropbox" />

我很想知道是否有更优雅的解决方案。我已经尝试为“cropbox”id设置attr'src'标签,但它需要先在里面执行PHP代码。有什么想法或建议吗?

1 个答案:

答案 0 :(得分:1)

如果你想摆脱第二个GET,你可以使用第一个GET中加载的img标签(当然是图像),并用css调整大小到你的缩略图的大小。