奇怪的行为,WAMP - Codeigniter

时间:2015-12-14 08:47:58

标签: php jquery forms codeigniter wamp

背景:我从Windows 7将Codeigniter项目迁移到Windows 10,在Windows 7中,我正在手动安装Apache,PHP,Mysql,但在Windows 10中我安装了WAMP。需要注意的是,mysqli在这个新的设置中没有工作,我尝试过很多东西并在这里提出问题,但无济于事。所以我现在正在使用mysql。

问题:我开始测试网站的功能(已迁移的项目),并发现注册无法正常工作,这在Windows 7安装程序中运行良好。表单被提交给保存表单html的同一个控制器。当用户单击提交按钮时,jquery执行一些操作然后返回true以提交表单。

问题是,控制器确实加载以响应表单提交但没有发布数据,但是如果我将操作URL更改为测试脚本,则表明表单正在正确提交并且有帖子数据。

在application / config / routes.php中重新路由:

$route['(?i)Signup/(:any)'] = 'Signup/index/$1';

控制器:

public function index ( $key = NULL )
{
    /** Does nothing */
    if ($_SERVER['REQUEST_METHOD'] == 'POST') print_r($_POST);

    if (  isset ( $key )  )
    {
       return $this->_key( $key );
    }
    /** Register. */
    if (   $this->input->post ( 'register_user' )  )
    {
        echo 'register_user';
        return $this->_register (  );
    }
    /** File upload Ajax call. */
    else if (  ! $this->input->post ( 'register_user' )  &&  $this->input->post ( 'gender' ) && $this->input->post ( 'ajaxUpload' )  )
    {
        echo 'ajaxUpload';
        echo $this->_upload (  );
    }
    /** Email Validation Ajax Call. */
    else if (  ! $this->input->post ( 'register_user' )  &&  $this->input->post ( 'email_validation' )  &&  $this->input->post ( 'email' )  )
    {
        echo 'email_validation';
        echo $this->_email_available (  );
    }
    /** Default view. */
    // If I submit form or not, this section is what gets executed
    else 
    {
        echo 'else';
        $this->_default (  );
    }
}

查看文件:

<form id="sign_up" action="<?php echo site_url (  ) . $this->router->fetch_class (  ) ;?>" method="post" accept-charset="utf-8" enctype="multipart/form-data">
    <input id="register_user" type="hidden" name="register_user" value="Submit" />
    ---
    ---
    <button type="submit" name="register_user" id="register_user" value="Submit">Submit</button>
</form>

JavaScript文件:     var sentinel = false;

$( '#sign_up' ).submit ( function ( event ) {
    if ( ! sentinel )
    {
        var scriptUrl = $ ( '#sign_up' ).attr ( 'action' );
        var data = new FormData (  );
        /* Appaend form data with the formData object */
        ---
        ---

        $.ajax ( {
            method : 'POST', url : scriptUrl, data : data, cache : false, processData: false, contentType: false, dataType : 'json',
            success : function ( data, textStatus, jqXHR ) { 

                /** Success uploading file, File saved to the server and server did not set the data.error variable/key. */
                if ( typeof data.error === 'undefined' )
                {
                    /** DO stuff */

                    sentinel = true;
                    $( '#sign_up' ).submit (  );
                }
                else
                {
                    /** Set error message and do nothing. */
                }
            },
            error : function ( jqXHR, textStatus, errorThrown ) 
            {
                alert (  jqXHR.responseText  );
            }

        } );
    }

    // return false - cancels original submits until allowed
    // returns true - allows a triggered submit
    return sentinel;
}

1 个答案:

答案 0 :(得分:0)

问题在于mod_rewrite。一旦我在Apache的httpd.conf文件中取消注释了行LoadModule rewrite_module modules/mod_rewrite.so,如果安装了Apache,它就会驻留在conf目录中。它可以工作。