‘壹’ thinkphp js文件里怎么使用框架url变量
在调用这个js文件的模板文件中,在调用js之前,加上这句:<script> var publicurl='__PUBLIC__'; </script> ;然后在js文件中使用publicurl这个变量就行了。
‘贰’ 如何消除PHP和JS 对URL编解码的不同之处,统一前后端对URL的编解码
json_encode()用eval()还原
base64_decode()用base64_encode()还原
数组是searialize()unsearialize。如果你还有想了解的可以去后盾人试试,这样会有不错的效果视频也不错 ,你有时间可以去试试
‘叁’ 关于PHP URL加密与JS url解密问题
别用 urlencode()函数, 用这个rawurlencode()函数就OK啦。
‘肆’ thinkphp下,js怎么不能用url地址,即__URL__ 只能用pathinfo模式
$.ajax({
type: "POST",
url: "__URL__/Mlife/userInfo"
这个ajax中的url。__URL__这个是识别不了的
可以用 U方法
你想要写全地址,可以在后台获取当前url传个变量过来。
用js得到你要的url 或者在当前页面中去合出来要用的url
‘伍’ js和php如何获取当前url的内容
#测试网址:
http://localhost/blog/testurl.php?id=5
复制代码
代码如下:
//获取域名或主机地址
echo
$_SERVER['HTTP_HOST']."<br>";
#localhost
//获取网页地址
echo
$_SERVER['PHP_SELF']."<br>";
#/blog/testurl.php
//获取网址参数
echo
$_SERVER["QUERY_STRING"]."<br>";
#id=5
//获取用户代理
echo
$_SERVER['HTTP_REFERER']."<br>";
//获取完整的url
echo
'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo
'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
#http://localhost/blog/testurl.php?id=5
//包含端口号的完整url
echo
'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
#http://localhost:80/blog/testurl.php?id=5
//只取路径
$url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"];
echo
dirname($url);
#http://localhost/blog
javascript实现:
复制代码
代码如下:
top.location.href
顶级窗口的地址
this.location.href
当前窗口的地址
‘陆’ thinkphp5引用的js文件url使用的问题
在.js文件中使用相对路径的时候,这个相对路径是针对引用这个.js文件的页面来说的.
不同目录级别下的东西引用相同的.js引起的相对路径是不同的。不过你可以写绝对路径。如dd\ff\kk.jpg。当然,相对路径可以写..\..\kk.jpg;..\kk.jpg等。
‘柒’ php怎么解码js编码过的url
json_encode()用eval()还原
base64_decode()用base64_encode()还原
数组是searialize()unsearialize()
‘捌’ php或js取url参数跳转链接
function GetQueryString(name)
{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null)return unescape(r[2]); return null;
}
例: .com?id=123&name=
alert(GetQueryString("id"));
此时就能弹出123了
‘玖’ php或者js如何取得完整url包括url中含有#的部分,比如:index.php#ac=5
用js的window.location.href,下面是代码:
function test() {
alert(window.location.href);
}
<a href="#" onclick="test()">test</a>
‘拾’ PHP或JS或html获取当前url
<!doctypehtml>
<html>
<head>
<metacharset="utf-8">
<title>test</title>
<script>
/.com$/i.test(location.hostname)?alert('安全'):alert('来路不正确');
</script>
</head>
<body>
<pid="htmltest">test</p>
</body>
</html>