AngularJS中的JSONP请求不像jQuery那样工作

JMa*_*lin 2 jquery jsonp angularjs angularjs-service

我想用AngularJS的$ http服务请求Dailymotion API,但它似乎不像jQuery那样工作.

var url = 'https://api.dailymotion.com/videos?fields=id,audience,onair&ids=xzttq2_c,xrw2w0';
Run Code Online (Sandbox Code Playgroud)

请求使用jQuery

jQuery.ajax({
  type: 'GET',
  url: url,
  dataType: 'jsonp',
  success: function(data) {
    console.log('Success', data);
  },
  error: function(data) {
    console.log('Error', data);
  }
});
Run Code Online (Sandbox Code Playgroud)

结果

使用jQuery,它工作正常.我不必使用回调.

Success 
Object {page: 1, limit: 10, explicit: false, has_more: false, list: Array[2]}
Run Code Online (Sandbox Code Playgroud)

请求使用AngularJS

$http({
    method: 'jsonp',
    url: url,
    responseType: "json"
}).
success(function (data) {
    console.log('Success', data);
}).
error(function (data) {
    console.log('Error', data);
});
Run Code Online (Sandbox Code Playgroud)

结果

但是对于Angularjs,它并没有像我预期的那样工作.

Uncaught SyntaxError: Unexpected token : 
Run Code Online (Sandbox Code Playgroud)

Che*_*niv 7

将其添加到您的网址:&callback=JSON_CALLBACK.

工作:http://jsfiddle.net/dqcpa/

从jQuery的ajax方法文档:

"jsonp":使用JSONP加载JSON块.添加额外的"?callback =?" 到URL的末尾以指定回调.