0
您好我正在尝试将yelp api集成到我的角度应用程序中。Angularjs与承诺的多个JSONP调用
var params = {
callback: 'angular.callbacks._0',
location: 'San+Francisco',
oauth_consumer_key: 'xxxxxxx', //Consumer Key
oauth_token: 'xxxxxxxxxxxx', //Token
oauth_signature_method: 'HMAC-SHA1',
oauth_timestamp: new Date().getTime(),
oauth_nonce: Math.random().toString(36).substring(7),
term: 'Itailian',
limit: 5
};
var consumerSecret = 'xxxxxxxxxxxxxx';
var tokenSecret = 'xxxxxxxxxxx';
function generateSignature(method, yelpURL, params, consumerSecret, tokenSecret) {
return oauthSignature.generate(method, yelpURL, params, consumerSecret, tokenSecret, {encodeSignature: false});
}
params['oauth_signature'] = generateSignature(method, yelpURL, params, consumerSecret, tokenSecret);
//Doest work even if I push below call in array and then do $q.all(promisesArra).
var defered = $q.defer();
$http.jsonp(yelpURL, {params: params})
.success(function (data) {
defered.resolve(data);
$localStorage[cusine] = data;
})
.error(function (error) {
console.log('failed', error);
});
return defered.promise;
我想为不同的术语例如多个呼叫:意大利,墨西哥,.. 我可以做一个JSONP呼叫,但不是多个。
我不知道的问题。我想这是因为回调的角度是硬编码的只能是angular.callbacks._0
尝试使用'.then',而不是'.success' – SuperVeetz