Ajax发布到codeigniter控制器给404,但它到控制器?

时间:2015-03-31 18:19:08

标签: php ajax codeigniter post

这对我和我的团队在本地工作非常合适,但是一旦我们将它拉到实时服务器并尝试它,它会给我一个404错误但仍然提供控制器中登录功能的错误响应。我现在已经试图解决这个问题好几个小时而没有运气,其他帖子也没有帮助。我希望它有点愚蠢,我没有看到。

编辑:最重要的部分是发布数据不会在服务器上发送,而是在本地发送。

Ajax电话:

    var username = $('#loginUsername').val();
    var password = $('#loginPassword').val();

    var data = {
        "username": username,
        "password": password
    };

    $.ajax({
        type: "POST",
        url: "<?php echo base_url(); ?>login",
        data: data,
        success: function(response) {
            //response code
        }
    });

调用控制器功能:

public function login() {
    $data = $_POST;

    if(!$data) {
        //error code
    } else {
        //success code
    }
}

如果有帮助,请点击.htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>

2 个答案:

答案 0 :(得分:1)

如果它在localhost上运行良好,那意味着你可能是你的控制器名称,你写的是区分大小写的问题。所以首先检查区分大小写的问题 比试试吧  url: "<?php echo site_url('controllerName/functionName'); ?>"

答案 1 :(得分:0)

我是个白痴。服务器上未启用Mod_rewrite。我认为这是因为其他功能正好像它们一样工作,可能是由于路由。