Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] CodeIgniter and Ajax with Jquery
#1

[eluser]Đaяк Đaηтє[/eluser]
I'm a beginner with codeigniter and I have no doubt about is a very useful framework and development tool, but I have some questions for you.

I have a simple applicattion for autenticate users to my page, I have a login view, a login model and a login controller and they interact with each other, it's really simple, but i have a question, when I make an ajax request with jquery I can specify an url like controller/function, for example
Code:
$.ajax({
          url        :     "index.php/login",
          type    :     "POST",
          cache    :     false,
        beforeSend: function()
                    $('#content').attr('innerHTML', '<div align="center">Cargando datos...</div>');
                },
          success    :     function(result)
                {
                    $('#content').attr('innerHTML', result);
                  }
    });

This works fine, but I don't want to show index.php in the url of the jquery ajax function, I would like to make an request with only the controller name, like this
Code:
url        :     "/login",
when I use the JQuery Ajax function, is this possible?

What can I do to achieve this?
#2

[eluser]Johan André[/eluser]
use .htaccess.
read the userguide.
#3

[eluser]Đaяк Đaηтє[/eluser]
Thanks, I use .htaccess file and it works fine, I have a comment to this, for recent version of apache we need to use ? symbol like this:
Code:
<IfModule mod_rewrite.c>  
     RewriteEngine on  
  
     RewriteCond %{REQUEST_FILENAME} !-f  
     RewriteCond %{REQUEST_FILENAME} !-d  
     RewriteRule ^(.*)$ index.php?/$1 [L]  
</IfModule>  
  
<IfModule !mod_rewrite.c>  
     ErrorDocument 404 /index.php  
</IfModule>

Without it, the RewriteRule doesn't work...

Thank you very much.




Theme © iAndrew 2016 - Forum software by © MyBB