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,知道的不多,希望知道的大家能帮忙解答一下,谢谢!
添加回答
举报
0/150
提交
取消