相关疑难解决方法(0)

替代https://gdata.youtube.com/feeds/api/videos/<video_id>?v=2

这些天我注意到我在项目中使用的Youtube API已不再可用,例如

https://gdata.youtube.com/feeds/api/videos/dLEk9yiXVQs?v=2

返回HTTP 410响应代码,这意味着请求的资源不再可用,并且将不再可用.

我应该用什么呢?

youtube-api http-status-code-410

35
推荐指数
1
解决办法
3万
查看次数

JsonP返回"Uncaught SyntaxError:Unexpected token:"AngularJS - routingnumbers.info

我研究这个问题是一个荒谬的数字,并希望有人可以帮助诊断出错了什么.

我已经尝试过查看以下SO问题:(因为声誉,所以我不会发布超过2个链接,所以我只是包含了这些路径)

  1. 问题/ 16344933/angularjs-JSONP - 不工作/ 16352746#16352746
  2. 问题/ 19269153/JSONP请求功能于angularjs-犯规工作样的-的jQuery
  3. 问题/ 19669044/angularjs-越来越语法错误 - 在 - 返回 - JSON-从-HTTP-JSONP

在众多......

我尝试过的事情: 我已经在网址的末尾添加了&callback = JSON_CALLBACK.我更改了配置设置,例如responseType:'JSON'.我还多次重新安排了http.jsonp请求,以确保它不是编程/文本(http({})和http.jsonp)

这是我正在尝试做的事情:使用角度jsonp请求 从routingnumbers.info/api/获取信息(服务器不允许CORS).我能够使用jQuery成功地提出请求,但我无法使用angular成功.

这是相应的测试小提琴: http ://jsfiddle.net/dqcpa/14/

如您所见,我收到两个错误:

  1. 资源解释为脚本但使用MIME类型text/plain传输:" https://routingnumbers.herokuapp.com/api/data.json?rn=071000013&callback=angular.callbacks._0 ".angular.min.js:97
  2. 未捕获的SyntaxError:意外的令牌:

但是如果你检查chrome devtools中的响应 - NETWORK,它是正确的:虽然我知道jsonp会返回jsonpfunction({"MyJson":"Data"})里面的响应,这是它被挂起的地方.

这是原始代码:

//$scope.number = '071000013';
var routingApiUrl = 'https://routingnumbers.herokuapp.com/api/data.json?rn=' + $scope.number;
$http({
    method: 'jsonp',
    url: routingApiUrl + '&callback=JSON_CALLBACK',
    responseType: "json"
}).
success(function(data){
    console.log('Success: ' + data);
}).
error(function(data){
    console.log('Error: ' + data);
}); …
Run Code Online (Sandbox Code Playgroud)

jquery json jsonp angularjs angular-http

18
推荐指数
1
解决办法
6万
查看次数

如何发出jsonp请求

我需要做一些跨站点脚本.下面的代码块包含jsonp的方法,该方法返回就好像失败了,但当我将其更改为get请求时,我就获得了成功.我需要能够使用jsonp方法成功响应.可以排除以下内容.响应是有效的json,这个param在url?callback = JSON_CALLBACK中.这是我通过执行http请求获得的json以及执行此代码的代码块.

http响应状态码200

[{"cube":"1" ,"points":"160"},{"cube":"2","points":"690"},{"cube":"3","points":"331"}]
Run Code Online (Sandbox Code Playgroud)

代码块

 var myApp = angular.module('test', []);

    myApp.controller('UserCtrl', function($scope, users) {
        $scope.usersPerCube = users.getUsers();
    })

    myApp.factory('users', function($http) {
       return {
         getUsers: function() {
           var deferred = $q.defer();
           var url = "http://localhost/api/api/index.php/analytics/UsersPerCube?callback=JSON_CALLBACK";
         $http.get(url).success(function (data, status, headers, config) {
                console.log(data);
                deferred.resolve(data);
            }).error(function (data, status, headers, config) {
                //this always gets called
                console.log(status);
                deferred.reject(status);
            });
            return deferred.promise;

     }
   }
Run Code Online (Sandbox Code Playgroud)

请注意,我已编辑了我的服务器端代码,现在已收到

"angular.callbacks._1( {"cube":"1","points":"160"},{"cube":"2","points":"690"},{"cube":"3","points":"331"})"
Run Code Online (Sandbox Code Playgroud)

更新 以上内容有效,现在正在执行成功方法.我只需要弄清楚如何解析对象.一旦我找到答案,我会再次发帖.

javascript json angularjs

15
推荐指数
1
解决办法
4万
查看次数

angularjs $ http.jsonp即使收到200也会转到.error而不是.success

我正在构建一个AngularJS应用程序,它调用从数据库获取数据的NodeJS服务器.NodeJS返回JSON.stringify(someArrayWithData).

这是AngularJS代码:

$scope.getMainGroups = function(){
    $http.jsonp("http://127.0.0.1:3000/get/MainGroups?callback=JSON_CALLBACK").success(function(data, status, headers, config) {
            $scope.MainGroups = data;
        }).error(function(data, status, headers, config) {
            $scope.MainGroups = status;
        });
};
Run Code Online (Sandbox Code Playgroud)

即使我在chrome调试器中看到结果返回(200 ok),$ scope.MainGroups也会转到.error而不是成功.

我错过了什么?

angularjs

3
推荐指数
1
解决办法
8144
查看次数