在Codeigniter中设置交叉域 [英] Set Cross Domain in Codeigniter

查看:101
本文介绍了在Codeigniter中设置交叉域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行托管项目服务运行完美。

When ever I run hosted project service run perfectly..

当我测试与其他项目,给我错误或我无法得到服务的响应。
i尝试很多,但不工作

when i test with Other project that give me error or i could not getting response from Services. i try a lot but not working

我的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);
        }
    }

服务方 / p>

Service Side:

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);

    }

我该怎么办?

推荐答案

经过长期解决后

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/x-www-form-urlencoded",
                async: false,
                dataType: 'json',
                processData: false,
                cache: false,
                success: function (response) {
                    alert("valid response");
                },
                error: function (ErrorResponse) {
                    alert("error");
                }
            });
        }
        catch (error) {
        }
    }

这篇关于在Codeigniter中设置交叉域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆