阿贾克斯与jQuery的codeigniter。网址犯规门禁控制器门禁、控制器、网址、阿贾克斯

2023-09-10 20:01:26 作者:一生为一人

我是新来的codeigniter,不能让我的AJAX工作。 我想使链接内容加载到上单击主文档。 我看了看说明,但无法弄清楚。除了阿贾克斯返回所有作品警报('错误')消息。没有什么是loadded到< D​​IV ID ='load_here'>< / DIV> 也许我失去了一些东西在config.php?我需要加载一些库这个工作? 任何想法将是有益的 //主文档链接

I am new to codeigniter and cannot get my ajax to work. I am trying to make links load content into the main document on click. I looked for instructions but could not figure it out. All works except the ajax returns alert('ERROR') message. nothing is loadded into <div id='load_here'></div> Maybe I am missing something in config.php? Do i have to load some library for this to work? Any ideas would be helpfull //main document link

<span id='reg_link_rules'>Link</span>  
<div id='load_here'></div>

//控制器

// controller

class Register extends CI_Controller {
   public function hello()
   {
      echo 'hello';
   }
}

// jQuery的

// 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的网址不能访问控制器。 Z:/家庭/ codeigniter / WWW /注册/测试这是我认为它需要我

I think the problem is that the ajax url does not access the controller. Z:/home/codeigniter/www/register/test this is where i think it takes me

问题解决了,是 HTTP所需的网址:// codeigniter /索引。 PHP /注册/你好

推荐答案

尝试使用URL:/注册/你好

Try with url: "/register/hello".

可能达到目的。

通常我做了

<script type="text/javascript">
    base_url = '<?=base_url()?>';
</script>

在我的网页的开头,只是

At the beginning of my page and simply

base_url+"register/hello"

而不是

这使我的AJAX更可靠,甚至当/不正确。

That makes my ajax more reliable, even when / is incorrect.