将PHP变量传递给Java Script window.location

pix*_*key 3 javascript php window.location

我试图将一个php变量传递给一个java脚本window.location,它在从数据库中删除一个项目后将用户返回到当前列表视图.我似乎无法使语法正确.

码:

function confirmation(a) {
var currString = "<? echo $currString ?>";
var answer = confirm("Are you sure you want to delete this item?")
if (answer){
    alert("The item has been deleted")
    window.location = "list.php?s='. $currString .'&=delete=true&id=" + a;
}
else{
    alert("The item has not been deleted")
}
Run Code Online (Sandbox Code Playgroud)

Par*_*kar 9

试试这个:

function confirmation(a) {
    var currString = "<?php echo $currString ?>";
    var answer = confirm("Are you sure you want to delete this item?");
    if (answer){
        alert("The item has been deleted")
        window.location = "list.php?s=" + currString + "&=delete=true&id=" + a;
    }
    else{
        alert("The item has not been deleted");
}
Run Code Online (Sandbox Code Playgroud)