PHP $ _POST奇怪

时间:2017-07-08 17:40:00

标签: php jquery ajax post

通过ajax向POST发送POST时遇到问题。

服务器代码

<?php 
echo file_get_contents('php://input');
print_r($_POST);
exit(0);
?>

ajax请求

var data = {key: 'value', __appversion: 0, __appos: 'Android'}
jQuery.ajax({
            'url': the_url,
            'method': 'POST',
            'cache': false,
            'dataType': 'json',
            'data': data,
            'error': function (xhr, status, error) {},
            'success': function (data, status, xhr) {}
        });

使用chrome的开发控制台模拟移动设备,请求如下

Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8,id;q=0.6,ms;q=0.4
Cache-Control:no-cache
Connection:keep-alive
Content-Length:40
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Host: xxxx-censored-xxxx
Origin:http://xxxx-censored-xxxx
Pragma:no-cache
Referer:http://xxxx-censored-xxxx
User-Agent:Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36

Form Data

key: value
__appversion: 0
__appos: Android

结果是(我知道json部分)

os=Android__appversion=0&__appos=AndroidArray
(
    [os] => Android__appversion=0
    [__appos] => Android
)

问题是, 为什么提交给服务器的变量丢失了?与key变量一样,__appversion也缺失。

我期待print_r($_POST)给予Array('key' => 'value', '__appversion' => 0, '__appos' => 'Android');

我在PHP上做错了什么? WebFaction上的PHP 7.0.20。谢谢。

0 个答案:

没有答案
相关问题