简体   繁体   English

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

[英]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. 我使用来自JQuery的ajax来调用CodeIgniter控制器内的函数。 But im always getting the 400 Bad Request error, even when im only printing plain text from the function. 但是,即使我只是从函数中打印纯文本,我也总是会收到400 Bad Request错误。

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: 这是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. 标准CI配置具有允许的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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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