我想一个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")
}
试试这个:
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");
}
你考取PHP变量到JS变量var currString =“”;
和window.location
你又通过PHP变量这是错误的,
所以像这样做
window.location = "list.php?s=" + currString + "&=delete=true&id=" + a;
语法问题是由其他的答案解决,但是你需要照顾的增发: URI编码 ,当你在URL中使用它您的变量:
window.location = "list.php?s="
+ encodeURIComponent(currString)
+ "&=delete=true&id=" + a;
否则你将你的变量包含相同的字符遇到的问题&
。
echo "<script>alert('System info has been Save')</script>";
echo "<script>window.location='customer_detail.php?
customer_id=".$customer_id."'</script>";