So I got this controller Email_Controller.php, and whenever I try to call a function of it via JavaScript it just gives me this error:
- Fatal error: Class 'CI_Controller' not found in C:\wamp64\www\Projeto\application\controllers\Email_Controller.php on line <i>2</i>
My Controller looks like this:
<?php
class Email_Controller extends CI_Controller {
public function SendEmail(){
//SomeCode
}
}
any idea on whats going on? My Main Controller is just working fine...
this is my JS
function teste() {
var email = document.getElementById("email").value;
var name = document.getElementById("name").value;
jQuery.ajax({
type: "POST",
url: 'application/controllers/Main_Controller.php/SendEmail',
data: {Post_email: email, Post_name: name},
success: function (response) {
console.log("success");
console.log(response);
},
error: function(response){
console.log("error");
console.log(response);
}
});
}
My routes.php
$route['default_controller'] = 'Main_Controller';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
答案 0 :(得分:1)
找不到它,因为您在ajax中错误地链接了网址。
使用此命令:url: "<?php echo base_url('Main_Controller/SendEmail') ?>",
仅供参考,当您调用控制器时,不要使用扩展名.php。
答案 1 :(得分:0)
请更改正确的路径。记住首先在application / config / config.php
中设置config base_url$config['base_url'] = 'http://siteurl.com/';
然后在JS URL中设置正确的路径。
url: '<?php echo base_url();?>Main_Controller.php/SendEmail',