简体   繁体   中英

Ajax 400 Bad Request upon calling a CodeIgniter controller with JQuery

I have this problem. Im using ajax from JQuery to call a function inside a CodeIgniter Controller. But im always getting the 400 Bad Request error, even when im only printing plain text from the function.

Here is the code:

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!";
}

Here is the 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);

    });

Im always getting this response

jqXHR.responseText:
    An Error Was Encountered
    The URI you submitted has disallowed characters.

jqXHR.status: 400

textStatus: error

error: Bad request

Any hint or help of whats going on there will be greatly appreciated

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

has a semi colon in the url. change it to:

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

The standard CI config has an allowed character list for the URI. You can modify the regex to accept semi colons as well, but in this case it looks like you put that semi colon in there by accident.

the problem is within your url

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

should be

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM