[英]Refresh page after action in javascript
I have the following code, that let users crop their pictures. 我有以下代码,可以让用户裁剪照片。 What I try to do, is to refresh the page after the user croped his picture, to let him see the thumbnail preview. 我想做的是在用户裁剪图片后刷新页面,让他看到缩略图预览。 But I tried to put a refresh code every single place, and the refresh never work. 但是我试图在每个地方都放置一个刷新代码,并且刷新永远都行不通。 Any idea on how I can do this? 关于如何执行此操作的任何想法? (Or any idea on what I'm doing wrong?) (或者对我在做什么错有任何想法吗?)
EDIT: I want to do the same as http://demos.9lessons.info/cropimages/imagecrop.php but without the confirm window 编辑:我想做与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>
Put your page refresh code in complete call back 将页面刷新代码放入完整的回调中
Example: 例:
$.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);
}
});
Hope this will help !! 希望这会有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.