php – 带有codeigniter的ajax jquery.网址不访问控制器
发布时间:2020-05-25 08:51:33 所属栏目:PHP 来源:互联网
导读:我是codeigniter的新手,无法让我的ajax工作. 我试图在点击时将链接内容加载到主文档中. 我寻找指示,但无法弄清楚.除ajax之外的所有工作都会返回alert(‘ERROR’)消息.没有任何内容加载到 div id =load_here / div 也许我在config.php中遗漏了一些东西?我必须
|
我是codeigniter的新手,无法让我的ajax工作.
<span id='reg_link_rules'>Link</span> <div id='load_here'></div> //控制器 class Register extends CI_Controller {
public function hello()
{
echo 'hello';
}
}
// jQuery $(document).ready(function() {
$('#reg_link_rules').click(function(eve){
$.ajax({
type: "GET",url: "register/hello",complete: function(data){
$('#load_here').html(data);
},error: function(){alert('error');}
});
});
});
我认为问题是ajax url不能访问控制器. 问题解决后,网址需要为http://codeigniter/index.php/register/hello 尝试使用url:“/ register / hello”.可以做到这一点. 通常我做一个 <script type="text/javascript">
base_url = '<?=base_url()?>';
</script>
在我的页面的开头,简单地说 base_url+"register/hello" 代替 即使/不正确,这也使我的ajax更可靠. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
