[英]Refresh page after action in javascript
我有以下代碼,可以讓用戶裁剪照片。 我想做的是在用戶裁剪圖片后刷新頁面,讓他看到縮略圖預覽。 但是我試圖在每個地方都放置一個刷新代碼,並且刷新永遠都行不通。 關於如何執行此操作的任何想法? (或者對我在做什么錯有任何想法嗎?)
編輯:我想做與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>
將頁面刷新代碼放入完整的回調中
例:
$.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);
}
});
希望這會有所幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.