我怎样才能得到JSON响应(PHP)

时间:2017-05-04 05:27:12

标签: php angularjs

我正面临服务器响应的问题。我的目标是将一些数据发送到服务器,并在考虑发送数据的情况下获得一些响应。

这是我的要求:

$scope.getCities = function () {
        $http.post(getCity, angular.toJson({country: "Belarus"})).then(function (data) {
            $scope.cities = data.data;
            console.log( 'Success' );
        }, function (err) {
            console.log('err');
        });
    };

这是我的PHP代码:

<?php

$postdata = file_get_contents('php://input');
$request = json_decode($postdata, true);

$country = $request['country'];

//here goes some code

$arr = array('a'=>1, 'b'=>2); // just for example

header('Content-Type: application/json');

echo json_encode($arr);

?>

我在控制台中看到同样的错误: 无法加载资源:服务器响应状态为404(未找到)

这是我的getCity变量: 在模块中,我有休闲:

calcM.constant("getCity", "http://www.vashagent.by/city_request");

在.htaccess我有休闲:

RewriteRule ^city_request$ /wp-includes/getCitiesByCountry.php [L]

0 个答案:

没有答案