我有这个问题。我使用来自 JQuery 的 ajax 来调用 CodeIgniter 控制器中的函数。但是我总是收到 400 Bad Request 错误,即使我只从函数中打印纯文本。
这是代码:
class Prueba extends CI_Controller {
//Displays de page, the code here is irrelevant
public function index(){
$this->validar_sesion();
$ciclos= $this->recuperar_periodos_escolares();
$this->smartyci->assign('secciones', $this->session->userdata('secciones'));
$this->smartyci->assign('modulos', $this->session->userdata('modulosAutorizados'));
$this->smartyci->assign('ciclos',$ciclos);
$this->smartyci->display('v3/reportes/reporte_ranking_general.tpl');
}
//The function to be called with AJAX, it originally has more code,
//but for the tests I just echoed a plain string, which is never returned.
public function recuperar_instrumentos(){
echo "EXITO!";
}
这是javascript:
var url="148.209.25.135/evaluacionAdmin/index.php/prueba;";
function recuperar_instrumentos(idCicloEscolar){
var request=$.ajax({
type:"POST",
url:url,
data:{idCiclo:idCicloEscolar}
});
request.done(function(data){
$('#instrumento').html(data);
});
request.fail(function(xhr,textStatus,error){
$('#instrumento').html(xhr.responseText);
alert("status= "+textStatus+"\nerror= "+xhr.status+"\n"+error);
});
我总是得到这个回应
jqXHR.responseText:
An Error Was Encountered
The URI you submitted has disallowed characters.
jqXHR.status: 400
textStatus: error
error: Bad request
任何关于那里发生的事情的提示或帮助将不胜感激