1.javascript 用post的方法从本地的php那里获得json数据,能获得response,但是response里面的data数据总是多了几行代码。如下图。
下面是代码。
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
<table>
<tr ng-repeat="x in names">
<td>{{ x.Name }}</td>
<td>{{ x.Country }}</td>
</tr>
</table>
</div>
<script>
var recordtest=[
{"Name":"xiaomi","City":"sehnzhen","Country":"us"}
]
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http({
method:'POST',
url: 'login.php'
}).then(function successCallback(response) {
alert("success");
console.log(response);
$scope.names = response.records;
},function errorCallback() {
alert("error");
$scope.names = recordtest;
});
});
</script>
</body>
下面是php的代码
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
$outp = "";
if ($outp != "") {$outp .= ",";}
$outp .= '{"Name":"' . "华为" . '",';
$outp .= '"City":"' . "北京" . '",';
$outp .= '"Country":"'. "中国" . '"}';
$outp ='{"records":['.$outp.']}';
echo($outp);
?>
第一次用php,知道的不多,希望知道的大家能帮忙解答一下,谢谢!
在php.ini中的 always_populate_raw_post_data' 设置成 '-1',
注意
一、前面有个;一定要去掉,一般默认就是-1了千万要注意前面的;
二、一定要重启php和服务器.
三、这个错误的意思是那个函数马上要被去除了不要用了,你在你的代码中看看有没有$http_raw_post_data这个函数,如果有就用file_get_contents('php://input')代替diao
四、如果不行,就就接着看前三条,重点是前两条