weixin_33697898 2014-09-30 16:37 采纳率: 0%
浏览 18

Ajax调用后更新图像

I have some problems.

On click I rotate image with ajax and save new image. Everything is without page refresh. And problem is that old image won't refresh and put new refreshed image.

Also new image have same name like the old one.

QUESTION

My question is how to update img from folder without page refresh? Only after click class slika-rotiraj.

HTML :

<div class="slika">
    <div class="slika-obrisi"></div>
    <div class="slika-rotiraj"></div>
    <img src="uploads/87b6f334f30717343acd69f3962142a0_542ad975e424d.jpg" />
</div>

SCRIPT :

$(document).on("click", ".slika-rotiraj", function() {
    var slika = $(this).next("img").attr("src");
    var slika1 = $(this).parent();
    var slika2 = $(this).next("img");
    $(this).next("img").attr("src", slika);
    $.ajax({
        type: "POST",
        url: "rotiraj.php",
        data: {
            slika: slika
        },
        success: function(data) {

        }
    });
});
  • 写回答

3条回答 默认 最新

  • weixin_33744141 2014-09-30 16:40
    关注

    Give your tag an id and set the value of the 'src' attribute inside your success function of the ajax call.

    HTML

    <div class="slika">
        <div class="slika-obrisi"></div>
        <div class="slika-rotiraj"></div>
        <img id="myimage" src="uploads/87b6f334f30717343acd69f3962142a0_542ad975e424d.jpg" />
    </div>
    

    JS:

    $(document).on("click", ".slika-rotiraj", function() {
        var slika = $(this).next("img").attr("src");
        var slika1 = $(this).parent();
        var slika2 = $(this).next("img");
        $(this).next("img").attr("src", slika);
        $.ajax({
            type: "POST",
            url: "rotiraj.php",
            data: {
                slika: slika
            },
            success: function(data) {
                $("#myimage").attr('src', data);
            }
        });
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥20 verilog状态机方法流水灯
  • ¥15 pandas代码实现不了意图
  • ¥15 GD32H7 从存储器到外设SPI传输数据无法重复启用DMA
  • ¥25 LT码在高斯信道下的误码率仿真
  • ¥45 渲染完成之后将物体的材质贴图改变,自动化进行这个操作
  • ¥15 yolov5目标检测并显示目标出现的时间或视频帧
  • ¥15 电视版的优酷可以设置电影连续播放吗?
  • ¥50 复现论文;matlab代码编写
  • ¥30 echarts 3d地图怎么实现一进来页面散点数据和卡片一起轮播
  • ¥15 数字图像的降噪滤波增强