Welcome Guest, Not a member yet? Register   Sign In
Base URL issue? jQuery is getting confused, among other things...
#1

[eluser]slamtastic[/eluser]
Hey all. I'm still pretty new to CI and have run into this snag a couple times when building text projects. Basically, methods, links and pages get lost from time to time.

For instance, this simple jQuery function gives error that follows:

Code:
$(document).ready(function() {

    $('.link_home').click(function() {
        $('.header_image').slideDown(function() {
            $('.wrap-content').fadeOut(function() {
                $.post('/ajax_home/home', function(html) {
                    alert('hi');
                    $('.wrap-content').html(html);
                });
            });
        });
...

    });

Code:
POST http://xampp.local/ajax_home/home    http://xampp.local/ajax_home/home   404 Not Found 42ms

This is what my config file looks like:

Code:
$config['base_url']    = "http://xampp.local/testsite";
$config['index_page'] = "index.php";

My Xampp Vhost setup:

Code:
<VirtualHost *:80>
    DocumentRoot C:/xampp/htdocs/ci
    ServerName xampp.local
    ServerAlias www.xampp.local
</VirtualHost>

Finally, my local hosts file:
Code:
127.0.0.1    xampp.local localhost


Pretty dern straight ahead, right?! What am I missing here?
#2

[eluser]xwero[/eluser]
is ajax_home a controller?
#3

[eluser]slamtastic[/eluser]
ajax_home.php is a file that resides in the same dir as the other view files.

home is a method in ajax_home.php
#4

[eluser]pistolPete[/eluser]
[quote author="slamtastic" date="1234794207"]ajax_home.php is a file that resides in the same dir as the other view files.[/quote]

If it is a controller, it must be in ./system/application/controllers.
#5

[eluser]slamtastic[/eluser]
Right. But, it's not a controller. It's just another view file with a simple function:

Code:
function home() {
  echo "foo";
}
#6

[eluser]pistolPete[/eluser]
But if you want to access it like you wrote above, it must be a controller!
Have a look at the user guide: Controllers
#7

[eluser]xwero[/eluser]
You can't access view files directly, it always has to go through a controller. So if you put ajax_home.php in the application/controllers directory and change the code to
Code:
class Ajax_home extends Controller
{
   function home() {
     echo "foo";
   }
}
#8

[eluser]slamtastic[/eluser]
Thanks, all. That cleared things up.




Theme © iAndrew 2016 - Forum software by © MyBB