Ajax 400 使用 JQuery 调用 CodeIgniter 控制器时出现错误请求


Ajax 400 Bad Request upon calling a CodeIgniter controller with JQuery

我有这个问题。我使用 JQuery 中的 ajax 调用 CodeIgniter 控制器中的函数。但是我总是收到 400 错误请求错误,即使 im 只从函数打印纯文本。

这是代码:

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
任何

关于那里发生的事情的提示或帮助将不胜感激

var url="148.209.25.135/evaluacionAdmin/index.php/prueba;";

URL 中有一个分号。将其更改为:

var url="148.209.25.135/evaluacionAdmin/index.php/prueba";

标准 CI 配置具有 URI 的允许字符列表。您也可以修改正则表达式以接受分号,但在这种情况下,看起来您不小心将分号放在那里。

问题出在您的网址中

var url="148.209.25.135/evaluacionAdmin/index.php/prueba;";

应该是

var url="148.209.25.135/evaluacionAdmin/index.php/prueba";// delete extra semicolon