0
所以我是新角度,我是新的API的 我試圖創建thingy,在那裏我可以通過id獲取視頻信息,使用幾個教程和瀏覽器stackoverflow 我設法找到2個解決方案這個問題,但他們都沒有爲我工作。 首先我想用angularjs創建api
mvcApp.service('ApiCall', ['$http', function($http) {
var result;
this.GetApiCall = function() {
result = $http.get('https://hosting.com/webmasters/video_by_id?id=123456789')
.success(function(data) {
result = (data);
})
.error(function() {
alert('Something wrong');
});
return result;
}}]);
它採用良好的API鏈接,但返回No 'Access-Control-Allow-Origin' header is present on the requested resource
錯誤。
下一個解決方案,我發現是:
mvcApp.factory('json', function($http) {
return {
getInformation: function (name) {
var url = 'https://hosting.com/webmasters/video_by_id';
return $http.jsonp(url, {
params: {
id: name
}
});
}
}});
這一個返回的錯誤,因爲它不承認VAR爲紐帶,並返回video_by_id?id=123456789:1 Uncaught SyntaxError: Unexpected token :
錯誤。但是,當我對它進行修改並查看其他一些示例時,發現向鏈接添加擴展可修復此問題,但我沒有或不知道擴展。所以,任何幫助將是有價值的
我在你的代碼 –
中沒有看到_thumbsize_編輯。我刪除了它,因爲它對於 –
這個問題不是必須的,因爲某些原因,':1'仍然存在。來自哪裏,它看起來不像你的硬編碼查詢?在你提供的示例代碼中...這一次它是在一個不同的參數。 –