在Codeigniter中设置跨域

 蓝瑟 发布于 2023-02-11 16:10

什么时候我运行托管项目服务运行完美..

当我测试其他项目给我错误或我无法得到服务的响应.我尝试了很多但没有工作

我的Ajax电话:

self.ValidLogin = function () {
         try {
            $.ajax({
                type: "GET",
                url: "http://xxx.xxx.xxx.xxx/TEST/index.php/TestController/TestMethod?UserName=superadmin&Password=super",
                ,
                crossDomain: true,
                contentType: "application/json; charset=utf-8",
                async: false,
                dataType: 'json',
                cache: false,
                success: function (response) {
                    alert("valid response");
                },
                error: function (ErrorResponse) {
                    alert("error");
                }

            });
        }
        catch (error) {
            alert("Catch:" + error);
        }
    }

服务方面:

public function TestMethod()
    {
        parse_str($_SERVER['QUERY_STRING'],$_GET);
        $UserName = $_GET['UserName'];
        $Password = $_GET['Password'];

        $this->load->model('LoginModel');
        $result = $this->LoginModel->Login($UserName,$Password);

        header('Content-type: application/json');
        header('Access-Control-Allow-Origin: *');
        echo json_encode($result);

    }

我该怎么办?

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有