简体   繁体   中英

How to display message and retrieve filename using DOM?

I have a php script below known as cancelimage.php where it will display a cancel message:

<?php

$image_file_name = $_GET["imagefilename"];

    echo "$image_file_name Upload was Canceled";


?>

The problem is that when I click on the "Cancel" button, it does not display this message. Instead it displays the message "There was a error during file upload". I believe the reason this message is coming up instead is because I am stating "return stopImageUpload".

So what my question is that how can I return to stopImageUpload like I am doing now, but instead be able to display the cancel message instead of the message it is displaying now?

Below is my current attempt on trying to fix this but which has failed. Below shows both the cancel button function and the stopImageUpload function:

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;
}

Below is the cancel button which is suppose to retrieve a file name from the DOM:

<input type='button' name='imageCancel' class='imageCancel' image_file_name='" + imagefilename + "' value='Cancel' />

The problem seems to be this:

    if (success == 1) {

And this:

return stopImageUpload();

stopImageUpdate has 2 params - first being success if you call without success will be undefined (not 1). Fix might look like this:

return stopImageUpload(0, image_file_name); 

And in your stopImageUpload change the else to something like:

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

HTH

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM