普通网友 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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog