Ajax URL显示在服务器上找不到404,而是在本地代码签名器上工作?

发布于 2025-01-17 13:54:23 字数 2933 浏览 0 评论 0原文

在 codeigniter 项目上工作并创建了一个基于 ajax 的表单,其中国家、州和城市通过 ajax 添加到我的表单中,这是我的 ajax jquery 函数,

$('#country-dropdown').on('change', function() {
    var country_id = this.value;
    $.ajax({
        url: "<?=base_url();?>get-states",
        type: "POST",
        data: {
            countryId: country_id
        },
        success: function(result) {
            $("#state-dropdown").html(result);
            $('#city-dropdown').html('<option value="">Select State First</option>');
        }
    });
});

$('#state-dropdown').on('change', function() {
    var state_id = this.value;
    $.ajax({
        url: "<?=base_url();?>get-cities",
        type: "POST",
        data: {
            stateId: state_id
        },
        success: function(result) {
            $("#city-dropdown").html(result);
        }
    });
});

非常简单 这些是我的路线,

$route['get-states']['post'] = 'backend/admin/others/Ajaxcontroller/getStates';
$route['get-cities']['post'] = 'backend/admin/others/Ajaxcontroller/getCities';

我的控制器

    public function getStates()
    {
        $this->load->model('StateModel', 'states');

        $countryId = $this->input->post('countryId');
        $states = $this->states->getStates($countryId);
        
        $html = '<option>Select State</option>';
        foreach($states as $state) {
            $html .= '<option value="'.$state->id.'">'.$state->name.'</option>';
        }

        echo $html;
    }

    public function getCities()
    {
        $this->load->model('CityModel', 'cities');

        $stateId = $this->input->post('stateId');
        $cities = $this->cities->getCities($stateId);
        
        $html = '<option>Select City</option>';
        foreach($cities as $city) {
            $html .= '<option value="'.$city->id.'">'.$city->name.'</option>';
        }

        echo $html;
    }

和我的模型

 public function getStates($countryId)
    {
        $query = $this->db->query("SELECT id ,name FROM rvd_states WHERE country_id = $countryId ORDER BY name;");
        return $query->result();
    }

public function getCities($stateId)
    {
        $query = $this->db->query("SELECT id ,name FROM rvd_cities WHERE state_id = $stateId;");
        return $query->result();
    }

,它在我的本地主机中工作得非常非常好,但是当我将代码切换到生产时,相同的ajax显示找不到网址

任何想法或建议发生了什么,

我的网址也没有变化 当我在 localhost 时,此 url 返回数据

http://localhost/matrimonial/get-states

,但当我在生产中时,此 url

https://host.com/matrimonial/get-states

返回 404

我的 htaccess 文件

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

请提供帮助

working on codeigniter project and created a ajax based form in which country , state and cities are added in my form by ajax and this is my ajax jquery function

$('#country-dropdown').on('change', function() {
    var country_id = this.value;
    $.ajax({
        url: "<?=base_url();?>get-states",
        type: "POST",
        data: {
            countryId: country_id
        },
        success: function(result) {
            $("#state-dropdown").html(result);
            $('#city-dropdown').html('<option value="">Select State First</option>');
        }
    });
});

$('#state-dropdown').on('change', function() {
    var state_id = this.value;
    $.ajax({
        url: "<?=base_url();?>get-cities",
        type: "POST",
        data: {
            stateId: state_id
        },
        success: function(result) {
            $("#city-dropdown").html(result);
        }
    });
});

pretty simple
and these are my routes

$route['get-states']['post'] = 'backend/admin/others/Ajaxcontroller/getStates';
$route['get-cities']['post'] = 'backend/admin/others/Ajaxcontroller/getCities';

my controller

    public function getStates()
    {
        $this->load->model('StateModel', 'states');

        $countryId = $this->input->post('countryId');
        $states = $this->states->getStates($countryId);
        
        $html = '<option>Select State</option>';
        foreach($states as $state) {
            $html .= '<option value="'.$state->id.'">'.$state->name.'</option>';
        }

        echo $html;
    }

    public function getCities()
    {
        $this->load->model('CityModel', 'cities');

        $stateId = $this->input->post('stateId');
        $cities = $this->cities->getCities($stateId);
        
        $html = '<option>Select City</option>';
        foreach($cities as $city) {
            $html .= '<option value="'.$city->id.'">'.$city->name.'</option>';
        }

        echo $html;
    }

and my model

 public function getStates($countryId)
    {
        $query = $this->db->query("SELECT id ,name FROM rvd_states WHERE country_id = $countryId ORDER BY name;");
        return $query->result();
    }

public function getCities($stateId)
    {
        $query = $this->db->query("SELECT id ,name FROM rvd_cities WHERE state_id = $stateId;");
        return $query->result();
    }

it is working very very fine in my localhost but when i switched my code to production this same ajax shows not found url

any idea or suggestion what is happening there

also there is no change in my url
when i am in localhost this url returns data

http://localhost/matrimonial/get-states

but when i am in production this url

https://host.com/matrimonial/get-states

return 404

my htaccess file

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

please any help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩动你心 2025-01-24 13:54:23

发布您的 .htaccess 文件代码。

另请检查控制器文件名。在实时服务器上,控制器文件名的第一个字符应该大写。

Post your .htaccess file code.

Also check controller file name. On live server first character of Controller file Name should be capital.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文