php - 404 上的 http 请求
问题描述
当我尝试向 codeigniter 路由发出 ajax 请求时,出现 404 错误
项目的根文件夹是http://localhost/control_cuotas/
这是控制器(索引有效):
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Control_cuotas_controller extends CI_Controller {
public function index()
{
$data = array();
$tables = $this->getTables();
$data['tables'] = $tables;
$this->load->view('main/main_view', $data);
}
public function getData($data){
var_dump($data);
}
private function getTables(){
$sql = "SELECT TABLE_NAME "
."FROM INFORMATION_SCHEMA.TABLES "
."WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME LIKE 'datos_%'";
$query = $this->db->query($sql);
$tables = array();
foreach ($query->result() as $row){
$name = substr($row->TABLE_NAME,0,-2);
if(!in_array($name,$tables)){
array_push($tables, $name);
}
}
return $tables;
}
这是javascript:
$(document).ready(function(){
$('#tables').change(function(){
var selected = $(this).val();
$.ajax({
url:'getData/'+selected
});
});
});
}
这是路线
$route['getData/(:any)']['GET'] = 'control_cuotas_controller/getData/$1';
请求在以下 url 上完成
http://localhost/control_cuotas/getData/selected_value
解决方案
请检查 .htaccess 文件
并尝试此代码;
RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
或者
$(document).ready(function(){
$('#tables').change(function(){
var selected = $(this).val();
$.ajax({
url:'http://localhost/control_cuotas/getData/'+selected
});
});
});
}
推荐阅读
- varnish - 重新加载后清漆 FetchError 长达 30 秒
- gcc - 促进。使用短名称链接依赖项
- python-3.x - Pandas 在 read_csv 上弄乱了一个高分辨率整数
- python-3.x - 如何并行运行 bash 脚本
- javascript - 无响应的 UI 元素在调整大小后变得有响应
- javascript - 如何使用 aws ec2 浏览器连接到 http://localhost:4200
- javascript - 在 Salesforce(兔子洞)上检查时,阴影 DOM 未显示在带有阴影根的自定义元素中
- performance - 服务器可以从负载均衡器处理多少个 TCP 连接
- node.js - 如何减少 Ionic 4 编译时间
- javascript - POST 后获取响应