從事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 顯示找不到 url
任何想法或建議那里發生了什么
當我在本地主機中時,我的 url 也沒有變化這個 url 回傳資料
http://localhost/matrimonial/get-states
但是當我在生產這個網址時
https://host.com/matrimonial/get-states
回傳 404
我的 htaccess 檔案
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
請任何幫助
uj5u.com熱心網友回復:
發布您的 .htaccess 檔案代碼。
還要檢查控制器檔案名。在實時服務器上,控制器檔案名的第一個字符應為大寫。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/454045.html
