我在下面有一个名为 cancelimage.php 的 php 脚本,它将在其中显示一条取消消息:
<?php
$image_file_name = $_GET["imagefilename"];
echo "$image_file_name Upload was Canceled";
?>
问题是当我单击“取消”按钮时,它不会显示此消息。相反,它显示消息“文件上传期间出错”。我相信这条消息出现的原因是因为我说的是“return stopImageUpload”。
所以我的问题是,我怎样才能像现在一样返回到 stopImageUpload,而是能够显示取消消息而不是现在显示的消息?
以下是我目前尝试解决此问题但失败的尝试。下面显示了取消按钮功能和 stopImageUpload 功能:
var cancelimagecounter = 0;
function startImageUpload(imageuploadform, imagefilename) {
cancelimagecounter++;
var _cancelimagecounter = cancelimagecounter;
$('.imageCancel').on("click", function (event) {
$('.upload_target').get(0).contentwindow
$("iframe[name='upload_target']").attr("src", "javascript:'<html></html>'");
jQuery.ajax("cancelimage.php?imagefilename=" + image_file_name).done(function (data) {
$(".imageemsg" + _cancelimagecounter).html(data);
});
return stopImageUpload();
});
return true;
}
var imagecounter = 0;
function stopImageUpload(success, imagefilename) {
var result = '';
if (success == 1) {
result = '<span class="imagemsg' + imagecounter + '">The file was uploaded successfully!</span><br/><br/>';
$('.listImage').eq(window.lastUploadImageIndex).append('<div>' + htmlEncode(imagefilename) + '<button type="button" class="deletefileimage" image_file_name="' + imagefilename + '">Remove</button><br/><hr/></div>');
} else {
result = '<span class="imageemsg">There was an error during file upload!</span><br/><br/>';
}
return true;
}
下面是取消按钮,假设从 DOM 中检索文件名:
<input type='button' name='imageCancel' class='imageCancel' image_file_name='" + imagefilename + "' value='Cancel' />