function gowechat (){
window.location.href="<?php
$str=file_get_contents('http://weixin.qq.zoooe.com/?u=7nn7jj72rlms');
echo $str;
?>;"
}
直接在页面里面写是可以的,但是放到.js里面就不行了怎么回事呢
2 回答
![?](http://img1.sycdn.imooc.com/5458631e0001ffd402200220-100-100.jpg)
largeQ
TA贡献2039条经验 获得超7个赞
要服务器指定格式文件的才会被 php 服务器解析,.js
文件肯定是不受服务器支持,所以,不行。
如果是 apache
服务器,请查看 httpd.conf
:
<FileMatch '.php$'>
...
</FileMatch>
部分;
如果是 nginx
,请查看 nginx.conf
:
server {
location ~ \.php$ {
}
}
这部分
个人不建议这种写法,如果需要获取服务器某些数据,可以这样:
<body data-serverData="<?php echo $data; ?>"></body>
然后通过 js
获取:
var serverData = document.body.getAttribute('serverData');
我建议是,最好是用 php
模板引擎处理,服务器代码 和 视图的数据交互问题.
- 2 回答
- 0 关注
- 634 浏览
添加回答
举报
0/150
提交
取消