I obviously make a silly newbie codeigniter mistake - I can't hit the method in the class - why?

This is my first CI project, so forgive me.

I just can't use the method with an AJAX call. He continues to appear as 404 in the web inspector.

I have a controller called home.php. It works. I can land on my homepage.

Then I launch an AJAX call on a hang event

function showDataWindow(){ // i might switch this to data attr, but for now item IDs are contained in class var thisClass = $(this).attr('class'); var thisIDpos = thisClass.indexOf("id-")+3; var thisID = thisClass.substr(thisIDpos, 3); alert(thisID); // alerting correctly $.post('getMoreInfo', { ID: thisID}, function(data) { .. act on data 

I just can find the method I'm calling is getMoreInfo. Always 404.

I have the home.php class in my controllers and its default set, and it works because I come to my homepage and get the index. But this home controller also has my getMoreInfo function ...

 public function getMoreInfo() { $ID = $_POST['ID']; $this->load->model('Artist_model'); $assocReturned = $this->Artist_model->get_more_info($ID); echo json_encode($assocReturned); } 

And I feel that the tiny MC Hammer is guarding this feature. "You cannot touch it." He scoffs at my little parachute trousers and disappears slightly.

I think this should be how I make my URI in jQuery AJAX? I have an index rewrite in my htaccess (which I'm exactly foggy for sure)

 RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?$1 [L] 

But I tried almost every URI permutation in that AJAX call

 www.mySite.com/index.php/home/getMoreInfo index.php/home/getMoreInfo index.php/getMoreInfo /home/getMoreInfo home/getMoreInfo /getMoreInfo getMoreInfo 

!

And no one worked. So what kind of stupid mistake am I making?

+4
source share
1 answer

What you need depends on how your router is configured.

By default, the call will be /home/getMoreInfo , but can be changed if you reconfigure the router. Link: http://codeigniter.com/user_guide/general/routing.html

+1
source

Source: https://habr.com/ru/post/1435992/


All Articles