来自PHP-MVC中AJAX调用的控制器的错误调用模型

发布于 2025-02-13 14:11:09 字数 1682 浏览 0 评论 0原文

我正在使用Ajax

AJAX/VIEW

$(document).ready(function(){

    $('#u').change(function(){

        $('#u option:selected').each(function(){
            id_region = $('#u').val();
            
            $.ajax({
                method: 'POST',
                url: './Controllers/controllerTitles.php',
                data: {'data': id_region},
                success: function(data,status){                          
                    alert(data + " " +  status)
                }
            });


        });
        
    });
});

控制器

<?php 




class controllerTitles{



    public static function Academic($id_u){

            $d = array("id_u" => $id_u);

            $of=MvcModelT::consultA($d);

            $html = "<option value='0'>SELECT ONE</option>";
     
            foreach($ofs as $o){

                $html .= "<option value='".$o["id_of"]."'>".$o["name"]."</option>";

            }

            echo $html;             
            
        }


}



if(isset($_POST['data'])){
        $a = $_POST['data'];
        $menu1 = new controllerTitles();
        $menu1 -> Academic($_POST['data']);

 
}



?>

奏效,但在此行时会发生致命错误:

$of=MvcModelT::consultA($d);

实际上 致命错误:未知的错误:在D:\ Xampp \ htdocs \ mvc_proyect \ Controllers \ Controllers.php:29

如果我使用“传统”方法调用模型,则该方法有任何问题,我的意思是

view

<?php
    $menu = new controllerTitles();
    $menu -> Academic(234);
?>  

控制器与以前相同,

我不知道为什么从Ajax调用控制器,模型不起作用

I'm calling the MVC controller using AJAX

AJAX / view

$(document).ready(function(){

    $('#u').change(function(){

        $('#u option:selected').each(function(){
            id_region = $('#u').val();
            
            $.ajax({
                method: 'POST',
                url: './Controllers/controllerTitles.php',
                data: {'data': id_region},
                success: function(data,status){                          
                    alert(data + " " +  status)
                }
            });


        });
        
    });
});

CONTROLLER

<?php 




class controllerTitles{



    public static function Academic($id_u){

            $d = array("id_u" => $id_u);

            $of=MvcModelT::consultA($d);

            $html = "<option value='0'>SELECT ONE</option>";
     
            foreach($ofs as $o){

                $html .= "<option value='".$o["id_of"]."'>".$o["name"]."</option>";

            }

            echo $html;             
            
        }


}



if(isset($_POST['data'])){
        $a = $_POST['data'];
        $menu1 = new controllerTitles();
        $menu1 -> Academic($_POST['data']);

 
}



?>

actually this works fine BUT fatal error happens when calling the model, at this line:

$of=MvcModelT::consultA($d);

Fatal error: Uncaught Error: Class "MvcModelT" not found in D:\xampp\htdocs\MVC_proyect\Controllers\controllerTitles.php:29

if I call the Model using "traditional" method this works with any problem, I mean

VIEW

<?php
    $menu = new controllerTitles();
    $menu -> Academic(234);
?>  

CONTROLLER is the same as before

I don't know why model not work if controller is called from AJAX

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文