通过PHP变量到Java脚本[removed]的(Pass PHP Variable into Ja

2019-07-30 01:49发布

我想一个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")
}

Answer 1:

试试这个:

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


Answer 2:

你考取PHP变量到JS变量var currString =“”;

window.location你又通过PHP变量这是错误的,

所以像这样做

window.location = "list.php?s=" + currString + "&=delete=true&id=" + a;


Answer 3:

语法问题是由其他的答案解决,但是你需要照顾的增发: URI编码 ,当你在URL中使用它您的变量:

window.location = "list.php?s="
                + encodeURIComponent(currString)
                + "&=delete=true&id=" + a;

否则你将你的变量包含相同的字符遇到的问题&



Answer 4:

echo "<script>alert('System info has been Save')</script>";
echo "<script>window.location='customer_detail.php?
customer_id=".$customer_id."'</script>";


文章来源: Pass PHP Variable into Java Script window.location