我有以下代码,让用户裁剪他们的照片。我尝试做的是在用户弄错图片后刷新页面,让他看到缩略图预览。但我尝试在每个地方放置一个刷新代码,刷新永远不会起作用。有关如何做到这一点的任何想法? (或者对我做错了什么想法?)
编辑:我想和http://demos.9lessons.info/cropimages/imagecrop.php做同样的事情,但没有确认窗口
<script type="text/javascript">
function getSizes(im, obj) {
var x_axis = obj.x1;
var x2_axis = obj.x2;
var y_axis = obj.y1;
var y2_axis = obj.y2;
var thumb_width = obj.width;
var thumb_height = obj.height;
if (thumb_width > 0) {
$.ajax({
type: "GET",
url: "ajax_image.php?t=ajax&img=" + $("#image_name").val() + "&w=" + thumb_width + "&h=" + thumb_height + "&x1=" + x_axis + "&y1=" + y_axis,
cache: false,
success: function (rsponse)
{
$("#cropimage").hide();
$("#thumbs").html("");
$("#thumbs").html("<img src='images/" + response + "' />");
complete: function() {
location.reload(true);
}
}
});
} else
alert("Please select portion..!");
}
$(document).ready(function () {
$('img#photo').imgAreaSelect({
aspectRatio: '1:1',
onSelectEnd: getSizes
});
});
</script>
答案 0 :(得分:1)
将页面刷新代码置于完整回调中
示例:强>
$.ajax({
type: "GET",
url: "ajax_image.php?t=ajax&img=" + $("#image_name").val() + "&w=" + thumb_width + "&h=" + thumb_height + "&x1=" + x_axis + "&y1=" + y_axis,
cache: false,
success: function (rsponse) {
$("#cropimage").hide();
$("#thumbs").html("");
$("#thumbs").html("<img src='images/" + response + "' />");
},
complete: function() {
location.reload(true);
}
});
希望这会有所帮助!!