簡體   English   中英

使用JQuery調用CodeIgniter控制器時出現Ajax 400錯誤請求

[英]Ajax 400 Bad Request upon calling a CodeIgniter controller with JQuery

我有這個問題。 我使用來自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

任何提示或幫助那里發生的事情將不勝感激

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

網址中有半冒號。 更改為:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM