如何在有角度的$http服务请求中将JSONP指定为dataType

How do I specify JSONP as the dataType in an angular $http service request?

本文关键字:请求 JSONP dataType 服务 http      更新时间:2023-09-26

我熟悉使用jQuery的$.ajax:

$.ajax({
  url: //twitter endpoint,
  method:"GET",
  dataType:"jsonp",
  success:function() {
    //stuff
  }
});

如何为角度$http服务请求指定JSONP数据类型?

到目前为止,我已经尝试过这个:

$http.get({
  url: //twitter endpoint,
  dataType: "jsonp",
  success: function(){
    //stuff
  }
});

但它没有起作用。有什么想法吗?

您可以始终使用$http.jsonp(url).success(function() {} );

$http.jsonp

试试这个:

$http({
  method: 'JSONP',
  url: '/someUrl?cb=JSON_CALLBACK'
}).then(function (response) {
  // stuff
});