【问题标题】:Strange behaviour, WAMP - Codeigniter奇怪的行为,WAMP - Codeigniter
【发布时间】:2015-12-14 08:47:58
【问题描述】:

背景:我将 Codeigniter 项目从 Windows 7 迁移到 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;
}

【问题讨论】:

  • 你用的是什么版本的codeigniter?
  • @wolfgang1983 版本 3.0.0
  • 你检查了网络标签,表单提交后调用了什么url,有post数据吗?
  • @bIgBoY firebug- 它显示状态 404 但发布数据存在:o
  • 您是否创建了一个虚拟主机来保存您的项目?或者您是从http://localhost 运行的吗?我建议为您的每个项目创建一个虚拟主机see here for detials on how to do that

标签: php jquery forms codeigniter wamp


【解决方案1】:

问题出在 mod_rewrite 上。一旦我取消注释 Apache 的 httpd.conf 文件中的 LoadModule rewrite_module modules/mod_rewrite.so 行,如果安装 Apache,它位于 conf 目录中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-04
    • 1970-01-01
    • 2013-12-13
    • 2015-03-02
    • 2014-04-27
    • 1970-01-01
    • 2013-04-28
    相关资源
    最近更新 更多