链接ajax加载php和刷新div
问题描述:
我有一个系统上传图片,但我想添加选项来旋转图片使用Ajax,问题是,如果整个页面更新变量会话丢失,那么只需要更新图像所在的div。链接ajax加载php和刷新div
我不能使用的形式,因为该链接的形式,所以它必须是这样的,如果可能的话...
这就是我想:
的index.php
<?php session_start(); ?>
...
<form>
...
<div id="thumbs">
<?php
if(isset($_SESSION['sess_img'])){
echo '
<a href="#" class="link" data-artid="'.$_SESSION['sess_img'].'">Rotate</a>
';
}
?>
</div>
...
</form>
...
<script type="text/javascript">
$(function(){
$('.link').click(function(){
var elem = $(this);
$.ajax({
type: "GET",
url: "rotate.php",
data: "file="+elem.attr('data-artid'),
success: function(result) {
$("#thumbs").html(result);
}
});
return false;
});
});
</script>
rotate.php
<?php
session_start();
$route = 'uploads/img/';
$file = $_GET['file'];
rotateImage($route.$file, $route.$file, 90);
?>
的想法:
点击链接。
过程rotate.php
更新大拇指的div
问题:
这段代码什么也不做,就不会失败,但是不会运行PHP。
答
我觉得你的rotate.php
代码是不正确的。看看这个例子。也许它会帮助你:http://php.net/manual/en/function.imagerotate.php#refsect1-function.imagerotate-examples
什么是具体问题或问题?您提供了一些代码,但没有指示什么是或不在工作 – charlietfl
如果ajax调用成功,您是否可以使用css来旋转用户?就像添加'transform:rotate(90deg)'一样,如果用户想简单地旋转图片,就不需要刷新页面。 –
@charlietfl问题: 这段代码什么都不做,它不会失败,但不能运行PHP。 – GePraxa