简体   繁体   中英

How to solve this string literal error

This code below is giving me a unterminated string literal error, how can this be fixed?

below is javascript code (QandAtable.php).

$(".imageCancel").on("click", function(event) {

    var image_file_name = "<?php echo str_replace("\n", "", $image_file_name); ?>";

                  $('.upload_target').get(0).contentwindow
              $("iframe[name='upload_target']").attr("src", "javascript:'<html></html>'");

    jQuery.ajax("cancelimage.php" + image_file_name)
        .done(function(data) {

        $(".imagemsg" + _cancelimagecounter).html(data);
    });

    return stopImageUpload();

}); 

below is imagecancel.php script where the ajax links to:

...

    $image_file_name = $_GET["fileImage"]["name"];

        echo "File Upload was Canceled";

            $imagecancelsql = "DELETE FROM Image 
            WHERE ImageFile = 'ImageFiles/". mysql_real_escape_string($image_file_name)."'";

        mysql_query($imagecancelsql);

In error console it is showing it as: var image_file_name = "<br />

试试看,不用担心内部双引号,它不会影响您的javascript字符串

var image_file_name = "<?php echo str_replace("\n", "", $image_file_name); ?>";

I doubt if I got your question correct, but there are few issues in your code.

when you are using $_GET, I guess you are doing it wrong $_GET["fileImage"]["name"] since its the GET parameter it will be simply $_GET["fileImage"]

But even before doing this, you should be sending it in the proper $_GET parameter ie

jQuery.ajax("cancelimage.php?fileImage=" + image_file_name)

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