来自PHP-MVC中AJAX调用的控制器的错误调用模型
我正在使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论