Javascript AngularJS在发送请求时更改定义的标头
我正在运行一个angularjs应用程序,我很难找到为什么我的$http调用会更改我的请求头 我将想要的头定义为Javascript AngularJS在发送请求时更改定义的标头,javascript,angularjs,json,ionic-framework,Javascript,Angularjs,Json,Ionic Framework,我正在运行一个angularjs应用程序,我很难找到为什么我的$http调用会更改我的请求头 我将想要的头定义为'accept':'application/JSON'。但是当我查看请求头时,我看到Accept://* 我的代码是: .controller('StopDetailCtrl',函数($scope,$http){ $scope.info=fetch(); 函数fetch(){ var uriBuilderhttp://api.translink.ca/rttiapi/v1/stops/
'accept':'application/JSON'
。但是当我查看请求头时,我看到Accept://*
我的代码是:
.controller('StopDetailCtrl',函数($scope,$http){
$scope.info=fetch();
函数fetch(){
var uriBuilderhttp://api.translink.ca/rttiapi/v1/stops/55612?apikey=u8RWYB3HmxjsHenpDk0u'
$http({
方法:“JSONP”,
url:uriBuilder,
标题:{
“接受”:“应用程序/JSON”
}
}).then(函数成功回调(响应){
log('Success',JSON.stringify(response));
},函数errorCallback(响应){
log('Error',JSON.stringify(response));
});
}
})
uri确实返回一个值,但它是导致抛出错误的XML。
我不断返回的错误是一个json字符串:
{
"status": 404,
"config": {
"method": "JSONP",
"transformRequest": [
null
],
"transformResponse": [
null
],
"url": "http:\/\/api.translink.ca\/rttiapi\/v1\/stops\/55612?apikey=Y3pJJjLVyfPetMoowJP4",
"headers": {
"Accept": "application\/json, text\/plain, *\/*"
}
},
"statusText": "error"
}
网络开发控制台告诉我请求头是:
Referer: http://localhost:8100/?restart=125748
Accept: */*
Cache-Control: max-age=0
Accept://*
与我放置的头不同头:{'Accept':'application/JSON'}
我使用的api是:用头替换头:{'Accept':'application/json'//standard header syntax}..然后再试一次。可能涉及到一些CORS问题。这是一个CORS问题:-C