1

我有这个问题。我使用来自 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

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

4

2 回答 2

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

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

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

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

于 2013-09-19T16:37:11.063 回答
0

问题出在您的网址中

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

应该

var url="148.209.25.135/evaluacionAdmin/index.php/prueba";// delete extra semicolon
于 2013-09-19T16:39:44.037 回答