Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
从angular到php的POST数组_Php_Angularjs_Arrays_Json - Fatal编程技术网

从angular到php的POST数组

从angular到php的POST数组,php,angularjs,arrays,json,Php,Angularjs,Arrays,Json,我发布了一个从angular到PHP的数组。我发送的数组如下[92,70,86,62,75,84,95] 但是在php中它变成了这样-[92,70,86,62,75,84,95] 我对php的预期输出是 { 用户id:false, 数据:[92,70,86,62,75,84,95] } 我得到的结果是 { 用户id:false, 数据:[92,70,86,62,75,84,95] } 从angular过帐数据的代码为 php中的代码是 分别使用JSON.stringify和JSON_decode

我发布了一个从angular到PHP的数组。我发送的数组如下[92,70,86,62,75,84,95] 但是在php中它变成了这样-[92,70,86,62,75,84,95]

我对php的预期输出是 { 用户id:false, 数据:[92,70,86,62,75,84,95] } 我得到的结果是 { 用户id:false, 数据:[92,70,86,62,75,84,95] }

从angular过帐数据的代码为 php中的代码是
分别使用JSON.stringify和JSON_decode

Javascript

PHP


application/x-www-form-urlencoded不能使用任何复杂结构,只能使用键值字符串对。请考虑使用应用程序/JSON。不管是哪种方式,您都需要对PHP代码中的file_get_内容的结果进行json_解码。飞行前响应中的访问控制允许标头不允许请求标头字段内容类型。因此,请在服务器中配置您的访问控制允许标头side@UsamaIshaque无论哪种方式,你都应该得到那个错误。这表明表单是从localhost以外的其他地方提供的。解决了头问题,并使用了json_decode而不是json_encode,但仍然得到如下相同的输出{user_id:false,data:[73,66,75,70,94100,60,89,69,79]}
$scope.data = [92,70,86,62,75,84,95];
 $http({
         method: 'POST',
         url: 'http://localhost/learn_php/api/api_set_data/',
         data: $scope.data,
         headers: {
             'Content-Type': 'application/x-www-form-urlencoded'
           }
        })
        .success(function(data) {
           console.log(data);
        });
public function api_set_data(){

    $array['user_id']  = $this->session->userdata('user_id');
    $array['data'] =  file_get_contents("php://input");

    $serializedData = serialize($array);
    file_put_contents(APPPATH."assets/get_values.txt", $serializedData);

    echo json_encode($array);        
  }
data: JSON.stringify($scope.data)
$array['data'] =  json_decode(file_get_contents("php://input"), true);