Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php $\u POST变量未填充,而是$HTTP\u RAW\u POST\u数据获取数据_Php_Html_Json_Forms_File - Fatal编程技术网

Php $\u POST变量未填充,而是$HTTP\u RAW\u POST\u数据获取数据

Php $\u POST变量未填充,而是$HTTP\u RAW\u POST\u数据获取数据,php,html,json,forms,file,Php,Html,Json,Forms,File,我在javascript中使用此函数与服务器php脚本通信: ajax = function( url, ready, json=null, method = 'post') { var response, request = xhr(); request.open( method, url, true ); request.onreadystatechange = function() { if( request.readyState == 4

我在
javascript
中使用此函数与服务器php脚本通信:

    ajax = function( url, ready, json=null, method = 'post') {
    var response, request = xhr();
    request.open( method, url, true );
    request.onreadystatechange = function() {
        if( request.readyState == 4 ) {
            if( typeof ready == 'function' ){
                return ready( request );
            } else {    return JSON.parse( request.responseText );}
        } 
    }
    if(json !== null){
        request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
        return request.send( JSON.stringify( json ) );
    }else { return request.send( null );}
}
使用
post方法打开连接后,我进行了
XMLHttpRequest
。 我还将
setRequestHeader
设置为解析
JSON:(“内容类型”,“应用程序/JSON;字符集=UTF-8”)
我使用这个函数从
html表单
收集
数据

formToValues = function (id) {
    var i, values = {}, form = document.getElementById(id);
    //var fields = form.querySelectorAll('input,textarea,select'),
    for (i = 0; i < form.length ;i++) {
        if( form.elements[i].name !== "" ){
            values[form.elements[i].name] = form.elements[i].value;
        }
    }
    return values;
}


ajax('a.php', function(response){
    console.log(response);
}, formToValues("regForm") );
<form id="regForm" action="javascript:;" method="post" />
<p>
<label for="name">Name</label>
<input type="text" name="name" value="xhr" />

<label for="email">Email:</label>
<input type="email" name="email" value="ro@ew.gq" />

<label for="password">Password:</label>
<input type="password" name="password" value="pass" />

<input type="button" value="Search" />
</p>

现在我在
php
脚本中接收数据时遇到了一个liitle问题:
a.php

<?php
var_dump(  $GLOBALS );
$ar= array( "a"=>2,"b"=>3, "c"=>json_decode( $_REQUEST['params'] ));
echo json_encode($ar);
?>
现在我可以使用
php://input
不会有问题,但我担心安全性,而且它没有问题,还有一件事需要考虑:从php版本5.6.0开始$HTTP_RAW_POST_DATA-RAW POST DATA已弃用~那么我该怎么办?
当请求内容类型为
application/json
(仅
application/x-www-form-urlencoded
multipart/form data
)时,Tkanks

PHP不会填充$\u POST superglobal

建议使用
json\u decode()
php://input

    "array(7) {
  ["GLOBALS"]=>
  array(7) {
    ["GLOBALS"]=>
    *RECURSION*
    ["HTTP_RAW_POST_DATA"]=>
    string(51) "{"name":"xhr","email":"ro@ew.gq","password":"pass"}"
    ["_POST"]=>
    array(0) {
    }
    ["_GET"]=>
    array(0) {
    }
    ["_COOKIE"]=>
    array(0) {
    }
    ["_FILES"]=>
    array(0) {
    }
    ["_REQUEST"]=>
    array(0) {
    }
  }