[英]AJAX returning 404 Not Found
我正在尝试使用ajax调用从数据库中获取数据,但它返回此错误:
这是我的AJAX电话
$.ajax({
url : '<?php echo base_url('Create_controller/getCategory'); ?>',
dataType : 'json',
success: function(data) {
$(data).each(function(){
$('#create_category').append($('<option>', {
value: this.id,
text: this.category,
}));
})
},
error: function(errorw) {
alert("error");
}
});
这是我的Create_controller:
public function getCategory(){
$categories = $this->create_model->getCategory();
echo json_encode($categories);
}
这是我的Create_model:
function getCategory(){
$this->db->select('id, category');
$this->db->from('category');
$this->db->where('status', 1);
$this->db->order_by('category', 'asc');
$query = $this->db->get();
return $query->result();
}
我知道我的控制器和模型可以正常工作,因为我尝试使用print_r($this->create_model->getCategory());
在加载视图之前。
我已经搜索了3个小时,但是没有一个解决我的问题。
谢谢您的帮助。
只需检查您是否以post方法或get方法发布数据。 尝试使用以下函数来调用Ajax:
var request = $.ajax({
url: "yourURl",
type: "POST",
dataType: "json"
});
您的控制器不存在您期望的位置。 右键单击错误消息中的URL,如果您使用的是Chrome,请尝试“在新标签页中打开”。 这与Ajax无关。 它与您的MVC设置和路由有关。
这是暂时的,但要替换
'<?php echo base_url('Create_controller/getCategory'); ?>'
同
"<?php echo base_url('Create_controller/getCategory'); ?>"
并说是否可行...
此问题的原因是我忘记添加.htaccess
文件。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.