Home > Backend Development > PHP Tutorial > 如何不让smarty对url中的“&”转成“&”?

如何不让smarty对url中的“&”转成“&”?

WBOY
Release: 2016-06-23 13:27:01
Original
1029 people have browsed it

后台:

function save_sort_handler(){	//-----获取应该返回的地址-----//	$backUrl=R('backUrl','');	if(empty($backUrl) && isset($_SERVER["HTTP_REFERER"])){		$backUrl=$_SERVER["HTTP_REFERER"];	}	$GLOBALS['smarty']->assign("backUrl",$backUrl);	//----------------------//	$GLOBALS['smarty']->display("takeaway_sort.dwt");}
Copy after login


前台:
<script type="text/javascript">			alert('{$backUrl}');			var isComplete={$isComplete};						if(isComplete){				var result="保存成功!";			}			else{				var result="保存失败!";			}			if(confirm(result+" 是否返回?")){				location.href='{$backUrl}';			}			else{				var type='{$type}';				if(type!=''){					location.href="takeaway_sort.php?type={$type}&backUrl={$backUrl}";				}			}		</script>
Copy after login


后台的echo和前台的alert出的$backUrl分别为:


回复讨论(解决方案)

转义一下不行吗?

你的来源url地址是什么样子?是否也是被处理过的。

你在 $GLOBALS['smarty']->assign("backUrl",$backUrl); 之前看一下 $backUrl
echo $backUrl;
应该是已经变了,与 smarty 无关

alert({$backurl|smarty:nodefaults}) 试试

来源地址本身没有错,是经过smarty的填充后才出错的。这个问题解决了,把参数填充在一个input元素的value里面就正确了:

后台:$GLOBALS['smarty']->assign("backUrl",$backUrl); 

前台:

谢谢大家的热心帮忙,你们提供的解决方案我没试。纯散分吧。另外各位有时间可以看看我的这个水贴,关于职业发展的问题:

http://bbs.csdn.net/topics/391823338

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template