【问题标题】:Getting JSON payload return with 404 status and no POST data available获取带有 404 状态且没有可用 POST 数据的 JSON 有效负载返回
【发布时间】:2014-03-19 05:34:32
【问题描述】:

我在使用 ajax 身份验证调用时遇到了一个奇怪的问题。我看到这个问题偶尔会以不同的形式被问到,但没有适合我所有症状的答案。

我有一个运行在虚拟盒中的 ubuntu 服务器 12.04LTS VM 实例。虚拟机正在运行 apache2 和 php5。它偶尔会给我以下错误:

[ 1074.908203] ata3.00: exception Emask 0x0 SAct 0x0 SErr 0x0 action 0x6 frozen
[ 1074.909669] ata3.00: failed command: FLUSH CACHE
(blah blah blah...i'm typing this)
[ 1074.909934]          res 40/00:01:00:00:00/00:00:00:00:00/40 Emask 0x4 (timeout)
[ 1074.910844] ata3.00: status: { DRDY }

我确信这是因为 vm .vdi 在我的 WD Green 2TB 上,并且我正在运行一些虚拟货币守护程序,它们正在努力赶上他们的区块链。我有一个固态硬盘来替换明天到达的虚拟机的驱动器,所以我并不担心解决这个问题,但我确实觉得这可能是相关的

在全局 js 文件中,我有

$.ajaxSetup({
    dataType: 'json',
    type    : 'POST'
});

在其他 js 文件中我有一个简单的

$.ajax({
    url     : '/authenticate/login',
    data    : {
        email   : email,
        password: password
    },
    success : doLoginCallback
});

这发生在点击/触摸启动(这点上没有什么疯狂的)

在 chrome 和 firefox 中(使用 ie),我可以在 firebug 中验证参数是否正在传递给 web 服务器

Parametersapplication/x-www-form-urlencoded
email       user@domain.com
password    password1

Source
email=user%40domain.com&password=password1

我的Authenticate->login 方法:

class Authenticate extends Core
{
...

public function login()
{
    if($this->input->is_ajax_request())
    {
        $email = $this->input->post('email');
        $password = $this->input->post('password');
        $return = array('success' => false);

        if($email && $password)
        {
            ...(it's not getting this far)...
        }
        else
        {
            $return['err_data'] = array(
                'email'     => $email,
                'password'  => $password,
                'post'      => $_POST
            );
        }

        echo json_encode($return);
    }
    else
    {
        header('Location: /');
        exit();
    }
}
...
}

它以 json 格式响应,但状态为 404

{"success":false,"err_data":{"email":false,"password":false,"post":[]}}

"NetworkError: 404 Not Found - http://myvm/authenticate/login"

$_POST 数组似乎是空的...?

我认为这一定是我的 apache2 配置中缺少的东西;这一直有效,直到我不得不在这个 vdi 上创建一个新的 vm 实例。

TLDR,我知道,但感谢您的任何想法/帮助!

【问题讨论】:

    标签: php jquery json codeigniter apache2


    【解决方案1】:

    感谢@Lekensteyn 找到this 的答案,我发现没有启用 mod_rewrite。在 ubuntu 服务器中启用 apache2 的 mod 重写:

    sudo a2enmod rewrite
    

    然后重启apache

    /etc/init.d/apache2 restart
    

    【讨论】:

      猜你喜欢
      • 2013-10-11
      • 1970-01-01
      • 2015-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-11
      • 2018-02-16
      相关资源
      最近更新 更多