php 两次encodeURI,解决浏览器跳转请求页乱码报错找不到页面的bug

时间:2022-09-02 21:53:47

Not Found

The requested URL /index.php/XXX/mid/97329240798095910/bname/3000T/D/sname/水泥粉磨/uname/1#水泥磨/oname/前滑履油站1.html was not found on this server.

解决思路:

get 提交 参数中 含有中文,  如果是PHP,那前端需要两次 encodeURI,因为一次encodeURI还有一些字符不会被编码

  onclick="showRecord(this)" href="{:U('OilAnalysis/monitorRecord',array('mid'=>$vo['oid'],'bname'=>$vo['bname'],'sname'=>$vo['sname'],'uname'=>$vo['uname'],'oname'=>$vo['oname']))}"
var showRecord=function(e){
var hf=$(e).attr('href');
var url=encodeURI(encodeURI(hf));
// url=hf;
location.href=url;
} 后台php
$data['mid']=urldecode(urldecode(I('mid')));
$data['bname']=urldecode(urldecode(I('bname')));