用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2891|回复: 6
收起左侧

[讨论/交流] ci框架在html文件中用js调用接口,为什么总是禁止?

[复制链接]
发表于 2017-8-16 16:50:31 | 显示全部楼层 |阅读模式
在ci框架外的任何地方,打开这个html文件并不会禁止
发表于 2017-8-16 17:03:41 | 显示全部楼层
具体是什么错误?没看明白你说的什么
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2017-8-16 16:52:52 | 显示全部楼层
这是错误提示 Failed to load resource: the server responded with a status of 403 (Forbidden)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<script type='text/javascript'>
    function testJson(obj){
        var aaa=obj.ip+obj.pro+obj.city+obj.region;
        console.log(aaa);
    }
</script>
<script src="http://whois.pconline.com.cn/ipJson.jsp?callback=testJson" charset="utf-8" type="text/javascript"></script>
</body>
</html>
 楼主| 发表于 2017-8-16 17:27:23 | 显示全部楼层
我在ci框架的根目录下新建了test.html文件,内容是:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<script type='text/javascript'>
    function testJson(obj){
        var aaa=obj.ip+obj.pro+obj.city+obj.region;
        console.log(aaa);
    }
</script>
<script src="http://whois.pconline.com.cn/ipJson.jsp?callback=testJson" charset="utf-8" type="text/javascript"></script>
</body>
</html>

又在controller下新建了一个控制器,内容:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends CI_Controller {

        /**
         * Index Page for this controller.
         *
         * Maps to the following URL
         *                 http://example.com/index.html/welcome
         *        - or -
         *                 http://example.com/index.html/welcome/index
         *        - or -
         * Since this controller is set as the default controller in
         * config/routes.php, it's displayed at http://example.com/
         *
         * So any other public methods not prefixed with an underscore will
         * map to /index.html/welcome/<method_name>
         * @see https://codeigniter.com/user_guide/general/urls.html
         */
       
        public function test(){
                $this->load->view('home/test.html');
        }
}

然后通过浏览器访问../index.php/home/test

出现错误提示:
403 Forbidden

You don't have permission to access the URL on this server. Sorry for the inconvenience.
Please report this message and include the following information to us.
Thank you very much!
URL:         http://whois.pconline.com.cn:6060/ipJson.jsp?callback=testJson
Server:         all-whois-vm230-47.pconline.cnc
Date:         2017/08/16 17:24:56
Powered by Tengine/2.1.2



但是我把  上面test.html文件不放在ci 框架下面,用浏览器打开就没有问题
 楼主| 发表于 2017-8-16 17:34:10 | 显示全部楼层
上面说错了test.html文件在view/home底下,不在根目录
发表于 2017-8-17 10:51:57 | 显示全部楼层
看起来好像是你没有权限访问 index.php,你的服务器好像有点问题,具体什么问题,你提供的这些信息无法判断。
发表于 2017-9-13 15:52:16 | 显示全部楼层
留意看看,应用程序目录是否有,.htaccess文件。它会限制浏览器访问这个文件,并且,只针对 Apache(貌似,只有Apache吧)。

另外,在 CI 框架目录,system目录也有这个文件,同样是限制浏览器直接访问的。

本版积分规则