Home > Software engineering >  ajax url showing 404 not found on server but working on local codeigniter?
ajax url showing 404 not found on server but working on local codeigniter?

Time:04-01

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

CodePudding user response:

Post your .htaccess file code.

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

  • Related