0

我在下面有一个名为 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' />
4

1 回答 1

0

问题似乎是这样的:

    if (success == 1) {

还有这个:

return stopImageUpload();

stopImageUpdate 有 2 个参数 - 如果您没有成功调用,则第一个成功将是未定义的(不是 1)。修复可能如下所示:

return stopImageUpload(0, image_file_name); 

并在您的 stopImageUpload 中将 else 更改为:

result = '<span class="imageemsg">' + image_file_name + ' Upload Was Cancelled!</span><br/><br/>';

高温高压

于 2012-05-14T14:37:33.703 回答