我正在运行一个angularjs应用程序,我无法找到为什么我的$http
调用失败。
我在浏览器中输入网址我总是收到回复。 但是,当我通过$http
通过url请求失败。
我的代码是:
.controller('StopDetailCtrl', function($scope, $http) {
$scope.info = fetch();
function fetch(){
//This url works
// var uriBuilder = 'http://cors-test.appspot.com/test'
//This url doesn't
var uriBuilder = 'http://api.translink.ca/rttiapi/v1/stops/55612?apikey=u8RWYB3HmxjsHenpDk0u'
$http({
method: 'GET',
url: uriBuilder
}).then(function successCallback(response) {
console.log('Success', JSON.stringify(response));
}, function errorCallback(response) {
console.log('Error', JSON.stringify(response));
});
}
})
我不断收到后面的错误是一个JSON字符串这是不翔实。
{
"data": null,
"status": 0,
"config": {
"method": "GET",
"transformRequest": [
null
],
"transformResponse": [
null
],
"url": "http:\/\/api.translink.ca\/rttiapi\/v1\/stops\/55612?apikey=u8RWYB3HmxjsHenpDk0u",
"headers": {
"Accept": "application\/json, text\/plain, *\/*"
}
},
"statusText": ""
}
有没有我在$ http请求中丢失的东西?
我使用的API是:https://developer.translink.ca/ServicesRtti/ApiReference
检查浏览器开发工具网络中的实际请求本身的线索 – charlietfl
上传浏览器开发工具的图像..他们不告诉我任何事情。只是说'尝试加载资源时发生了错误' – Whitecat
arg ...现在我得到了开发错误XMLHttpRequest无法加载http://api.translink.ca/rttiapi/v1/stops/55612?apikey=u8RWYB3HmxjsHenpDk0u。来源http:// localhost:8100不被Access-Control-Allow-Origin所允许。# – Whitecat