$ .post到Codeigniter控制器/方法404页面未找到 [英] $.post to Codeigniter Controller/Method 404 Page Not Found

查看:69
本文介绍了$ .post到Codeigniter控制器/方法404页面未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了Codeigniter原型应用程序,并在开发阶段与Godaddy.com托管,用于测试目的,没有任何问题.此应用程序结合使用了javascript,jquery,HTML5,CSS和PHP(Codeigniter框架).本周,我已将应用程序转移到客户端服务器,并遇到了许多配置问题,但最终遇到了麻烦.

I have developed a Codeigniter prototype application and hosted with Godaddy.com during the development phase for testing purposes without issue. This application uses a combination of javascript, jquery, HTML5, CSS and PHP (Codeigniter Framework). This week I have transferred the application to the clients server and have had many configuration issues but finally hit a wall.

客户端使用PHP5在新的Linux/Apache2服务器上进行了全新安装.启用了mod_rewrite并将allowoverride设置为all.Apache2设置(每个客户端都是)...

The client set up a fresh install on a new Linux/Apache2 server with PHP5. mod_rewrite is enabled and allowoverride is set to all. The Apache2 settings (per the client are)...

我的.htaccess脚本(由于这个问题,我尝试了许多不同的.htaccess版本)...

My .htaccess script(since this issue I have tried many different .htaccess versions)...

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

我的用于将序列化表单数据发布到PHP页面的javascript代码...

My javascript code for posting serialized form data to PHP page...

        $.post('login_ctrl/authenticateuserlogon', $formData, function($responseData)
        {   
            $userAuthentication=$responseData.userAuthentication;

            if ($userAuthentication=='success')
            {
                window.location.href = "student_portal_ctrl";
            }
            else
            {                       
                $('#loginErrDiv').text('Username or Password is incorrect - Please try again.');
                return;
            }

        });         

我的codeigniter文件结构是...

My codeigniter file structure is...

-root /
       /CI
        /application
        /system
        /index.php
        /license.txt
        /.htaccess

当我发布到此控制器/方法时,浏览器输出...

When I post to this controller/method, the browser outputs...

-----编辑-----

对不起,忘了包括我的config.php设置,这里是...

Sorry, forgot to include my config.php settings, here they are...

 $config['base_url'] = '';
 $config['index_page'] = '';
 $config['uri_protocol']    = 'AUTO'; //I have tested the app using all of codeigniters 
                                      //default URI Protocols

-----编辑#2 -----

这是控制器上收到404错误的方法

This is the method on the controller that is receiving the 404 error

    //AUTHENTICATE USER LOGIN FUNCTION
public function authenticateuserlogon()
{
    //SETTING $FORMDATA TO SERIALIZED POST DATA
    $formData = $this->input->post();

    //Sets the Method for the login_mdl
    $modelMethod=$formData['modelMethod'];

    //LOADING USER AUTHENTICATION LOGIN MODEL
    $this->load->model('login_mdl');


    //SENDING FORMDATA TO MODEL AND RETURING DATA TO $RESPONSEDATA
    $responseData = array();
    $responseData = $this->login_mdl->$modelMethod($formData);

    //OUTPUTTING JSON RESPONSE DATA BACK TO JAVASCRIPT          
    $this->output->set_output(json_encode($responseData));          
}

推荐答案

使用此 .htaccess (该代码已由我测试并且运行正常)

Use this .htaccess which is tested by me and working fine

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /CI/

    #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
    #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>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.

    ErrorDocument 404 /index.php
</IfModule> 

,并在您的 config.php 文件中使用此

and in your config.php file use this,

$config['base_url'] = "http://".$_SERVER['HTTP_HOST'];

这篇关于$ .post到Codeigniter控制器/方法404页面未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆