Select2仅适用于localhost,在服务器上无效 - 使用codeigniter

时间:2014-12-03 16:46:54

标签: jquery-select2

如果有人可以帮我解决这个错误,我会非常感激。 我的htaccess或直接到我的代码有诀窍吗?


我的控制器名为jasontrend

类Jsontrend扩展了CI_Controller {

    function __construct()
    {
        parent::__construct();
    }


    public function index()
    {


        $input = (isset($_GET['term']))? trim($_GET['term']) : '';
        $return_arr = array();
        $row_array  = array();
        $query = $this
            ->db
            ->order_by('slug','ASC')
            ->like('slug', $input)
            ->get('trendmark');

            foreach($query->result() as $row):

                $row_array['slug']       = $row->slug;
                $row_array['id']         = $row->id;
                $row_array['titleMedia'] = utf8_encode($row->titleMedia);
                $row_array['fileMedia']  = $row->fileMedia;
                $row_array['url']        = $row->url;

                array_push($return_arr,$row_array);

            endforeach;

            header("Content-type: application/json");
            echo json_encode($return_arr);


        }

}

我的javascript:

$("#epop").select2({
    minimumInputLength: 2,
    placeholder: "DIGITE A MARCA DE SEU PRODUTO",

    ajax: {
        url: top.location.host == '127.0.0.1' ? 'http://127.0.0.1/mysite/jsontrend/' : 'http://mysite/jsontrend',
        dataType: 'json',
        data: function (term, page) {
        return {
            term: term,
            page: page || 1

        };
    },
    error: function (jqXHR, status, error) {
        console.log(error + ": " + jqXHR.responseText);
        return { results: [] }; // Return dataset to load after error
    },
    results: function (data) {
        //$('.searchtrend').attr('disabled',false);

        return {
            results: $.map(data, function (item) {
                return {
                    text: item.titleMedia,
                    url: item.url,
                    id: item.id,
                    slug: item.slug,
                    file: item.fileMedia

                }

            })
        };
    }
},
formatResult: repoFormatResult,
formatSelection: repoFormatSelection,
dropdownCssClass: "bigdrop"

});

htaccess的 RewriteEngine on RewriteRule ^ $ index.php [L] RewriteCond $ 1!^(index.php | run.php | fckeditor | assets | img | css | js | images | updin | stats | xml | admin | robots.txt | favicon.ico | favicon_adm.ico) RewriteRule ^(。*)$ index.php?/ $ 1 [L]

1 个答案:

答案 0 :(得分:0)

在PHP代码中编写您的URL,如下所示

ajax: {
   url:'<?php echo base_url('yourcontroller/') ?>',
   your other code here
}