Php 不带回调参数的JSONP数据的Angularjs$http get方法

Php 不带回调参数的JSONP数据的Angularjs$http get方法,php,angularjs,json,jsonp,http-method,Php,Angularjs,Json,Jsonp,Http Method,我在表中打印服务器上的一些JSON时遇到了问题。 这是我的JSON process([ { "name": "A", "value": "41" }, { "name": "B", "value": "71" }, { "name": "C", "value": "20" }],"2017.07.11 15:48:33"); 我的控制器: myApp.controller('liveTable', function ($scope, $http)

我在表中打印服务器上的一些JSON时遇到了问题。 这是我的JSON

process([
{
    "name": "A",
    "value": "41"
},
{
    "name": "B",
    "value": "71"
},
{
    "name": "C",
    "value": "20"
}],"2017.07.11 15:48:33");
我的控制器:

myApp.controller('liveTable', function ($scope, $http) {

$http.get('http://something.com/get.php?jsonp=2017')
    .then(function (response) {
        $scope.myData= response.data;
        console.log(response.data);
    });
这是我的HTML

 <div class="liveTable" ng-controller="liveTable">
             <table>
                <tr ng-repeat="item in myData.process">
                    <td>{{item.name}}</td>
                    <td>{{item.value}}</td>
                </tr>
            </table>

        </div>

{{item.name}
{{item.value}}
你知道我哪里错了吗?tnx

试试:

app.service("dangerousAPI", function($q) {
  this.get = get;

  function get(funcName, url) {
    var dataDefer = $q.defer();

    window[funcName] = function(x) {
      dataDefer.resolve(x);
    }

    var tag = document.createElement("script");
    tag.src = url;

    document.getElementsByTagName("head")[0].appendChild(tag);

    return dataDefer.promise;
  }
})
有关详细信息,请参阅


当我放置
{{myData}}
时,我有完整的jsonp


我很高兴你能用这个答案得到数据。这表明服务器没有返回合法的JSON。服务器应该固定为返回合法JSON或合法JSON

要使服务器使用有效数组进行响应,请将JSON包装在括号()中,并在回调前加上前缀:

echo $_GET['callback']."([{'fullname' : 'Jeff Hansen'}])";
Using json_encode() will convert a native PHP array into JSON:

$array = array(
    'fullname' => 'Jeff Hansen',
    'address' => 'somewhere no.3'
);
echo $_GET['callback']."(".json_encode($array).")";

有关更多信息,请参见

我认为您的json数据有问题

我可以通过更改json数据来查看。你可以看看


{{item.name}
{{item.value}}
angular.module(“myapp”,[]).controller(“myctrl”,函数($scope){
$scope.process=([
{
“姓名”:“A”,
“值”:“41”
},
{
“名称”:“B”,
“值”:“71”
},
{
“姓名”:“C”,
“值”:“20”
}]);
});

你在控制台中看到数据了吗?这看起来不像是有效的JSONY我在控制台中看到数据当我放入{{myData}}时,我有完整的jsonp,我想逐元素打印,知道吗?我很高兴你能用这个答案得到数据。这表明服务器没有返回合法的JSON。服务器应该固定为返回合法JSON或合法JSON。
echo $_GET['callback']."([{'fullname' : 'Jeff Hansen'}])";
Using json_encode() will convert a native PHP array into JSON:

$array = array(
    'fullname' => 'Jeff Hansen',
    'address' => 'somewhere no.3'
);
echo $_GET['callback']."(".json_encode($array).")";