Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
12
rated 0 times [  16] [ 4]  / answers: 1 / hits: 19307  / 12 Years ago, tue, may 1, 2012, 12:00:00

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



$(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 access the controller.
Z:/home/codeigniter/www/register/test this is where i think it takes me



problem solved, the url needed to be http://codeigniter/index.php/register/hello


More From » php

 Answers
41

Try with url: /register/hello.



Might do the trick.



Usually I do a



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


At the beginning of my page and simply



base_url+register/hello


instead



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


[#85868] Sunday, April 29, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
deanna

Total Points: 84
Total Questions: 86
Total Answers: 107

Location: Cyprus
Member since Wed, Dec 8, 2021
3 Years ago
;