Ajax jquery with codeigniter. url does not get access to the controller

I am new to codeigniter and can't get my ajax to work.
I am trying to make links load content into the main document when clicked.
I was looking for instructions, but could not understand. All jobs except ajax return a message alert('ERROR'). nothing loads in <div id='load_here'></div>
Maybe something is missing for me in config.php? Do I need to download a library for this? Any ideas would be helpful // link to main document

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

//controller

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');}
    });
  });
});

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

the problem is resolved, the URL must be http: //codeigniter/index.php/register/hello

+5
6

url: "/register/hello".

.

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

base_url+"register/hello"

ajax , /.

+6
complete: function(data){
        $('#load_here').html(data);
    },

SO... success() complete() AJAX

success: function(data){
        $('#load_here').html(data);
    },

$.ajax({
  type: "GET", 

, URL.

$.ajax({
  type: "POST", 
+6

, url URL Ajax.

 $.ajax({
  type: "GET", 
  url: <?php echo base_url();?>"register/hello", 

  complete: function(data){
    $('#load_here').html(data);
},

, URL- !

0
you need to pass the bas_url to ajax file

<script type="text/javascript">

$(document).ready(function(e) {
    var baseurl = <?php echo base_url();?>

    $('#reg_link_rules').click(function(){

        $.ajax({
            url : baseurl+'index.php/register/hello',
            data : '',
            type: "POST",
           success : function(){


            }
        })
        return false;
    })

});

</script>
0

index.php . :

 $.ajax({
  type: "GET", 
  url: <?php echo base_url();?>"index.php/register/hello", 

  complete: function(data){
    $('#load_here').html(data);
},

. . , .

0

please specify your ajax part as url :? php echo base_url ();?> "register / hello" and enter: "GET", and you also need to check if the URL is being sent to config / rout.php.

0
source

All Articles