首页 > 解决方案 > 通过jquery调用对象函数

问题描述

大家好,我想公开一个问题......我的网络应用程序有这种情况:

//路线

getRoute()->post('/aggiungiMateria', array("GestioneController","aggiungiMateria"));

//控制器

function aggiungiMateria(){
    try{
        $model     = new GestioneModel();
        $alunno = $model->aggiungiMateria();
        echo 'ok';
    }catch(Exception $e){
        echo json_encode(array($e->getMessage()));
    }
}

//模型

function aggiungiMateria(){
    $nome = addslashes($_POST['nome']);
    try{    
        $db    = $this->getConnection();
        $query = $db->prepare("INSERT INTO materie SET nome = '$nome' ");
        $query->execute();
    }catch(PDOException $e){
        echo $e->getMessage();
    }
}

//HTML

<label>Materia</label>
<input type="text" id="nome" value="<?php echo $materia;?>" />                 
<input type="hidden" id="controllo" value="<?php echo $id?>"/>
<button onclick="gestione();">SALVA</button>

//JS AJAX

function gestione(){
    $('.loading').show();
    var nome = $('#nome').val();
    var id = $('#controllo').val();

    if(id!=''){

        $.post( "../../ws/modificaMateria", {       //NOT FOUND

            nome:nome,
            id:id
            }, 
            function( data ) {

                if(data=='ok'){
                    location.href='materie.php';
                }

            }, "html");
    }else{
        $.post( "../../ws/aggiungiMateria", {       //NOT FOUND

            nome:nome,
            id:id
            }, 
            function( data ) {

                if(data=='ok'){
                    location.href='materie.php';
                }

        }, "html");
    }
}

当单击 SALVA 按钮时,调试器会抛出 /ws/aggiungiMateria 的异常,错误 404 和来自 jQuery-2.1.4.min 的 f.send 给我来自 chrome 开发工具的未捕获错误。对于这篇文章中的任何错误,我深表歉意。

有什么建议吗?提前致谢。

标签: javascriptphpjquery

解决方案


我通过使用 AllowOverride All 指令修改 apache 配置文件来解决


推荐阅读