普通网友 2015-01-06 06:43
浏览 17

AJAX重新加载旋转图像

I'm currently using this: https://stackoverflow.com/a/24312826/1654748 to rotate my images.

I'm also using header('Location: url.php'); to redirect to the previous page, but the problem is, only about 30% of the time it reloads the rotated image.

The way I display the images is like this:

$result = mysql_query("SELECT * FROM `media` ORDER BY `id` DESC") or die(mysql_error());

while($row = mysql_fetch_array($result)) {
  echo '<div class="col-lg-3 imgauto">';
  echo '<div class="imagepad">';
  echo '<img src="uploads/'.$row['image'].'">';
  echo '</div>';
  echo '<a href="deletemedia.php?id='.$row['id'].'" data-href="deletemedia.php?id='.$row['id'].'" class="btn btn-danger imagecontrols imgdel" data-toggle="confirmation"><i class="fa fa-close"></i></a>';
  echo '<a href="#" class="btn btn-warning imagecontrols imgedit" data-toggle="modal" data-target="#myModal" href="#"><i class="fa fa-edit"></i></a>';
  echo '<form action="rotateimage.php" method="post">';
  echo '<input name="image" type="hidden" value="uploads/'.$row['image'].'">';
  echo '<button name="save" type="submit" class="btn btn-warning imagecontrols imgrotate"><i class="fa fa-rotate-right"></i></button>';
  echo '</form>';
  echo '</div>';
}

Is it possible to acheive the form action rotateimage.php without a page refresh, and reload the modified image with AJAX?

  • 写回答

1条回答 默认 最新

  • local-host 2015-01-06 07:12
    关注

    Put the form or button inside your main .php page (i.e. index.php) and the function that rotates the image and saves it in a separate php file (i.e. rotateImage.php) then use an ajax call to call rotateImage.php

    $("#flipPicture").click(function()
    {
        $.ajax({
            type:"POST",
            data{postVar:myVar}, //includes whatever variables you want to pass to your rotateImage.php page
            url:"rotateImage.php",
            success: function(data)
                     {
                         $("#imgContainer").html(data);
                     }
        });
    });
    

    where #flipPicture points to the id of the (say a button) element that rotates the picture and "data" is whatever your rotateImage.php echo's (your image flipped) and "#imgContainer" is the container for which the image will be placed (code from rotateImage.php)

    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀