Javascript Firefox中阻止跨源请求

Javascript Firefox中阻止跨源请求,javascript,java,asp.net,angularjs,Javascript,Java,Asp.net,Angularjs,当我们使用angularjs从服务器访问数据时,我们得到了一个CORSE错误 我们的守则: var app = angular.module("app", []); app.controller("Ctrl", function($scope, $http) { $scope.survey = true; $scope.question = false; $http.get("http://localhost:8081/NxtLife_Demo/getsurvey

当我们使用angularjs从服务器访问数据时,我们得到了一个CORSE错误

我们的守则:

var app = angular.module("app", []);
app.controller("Ctrl", function($scope, $http) {
    $scope.survey = true;
    $scope.question = false;
        $http.get("http://localhost:8081/NxtLife_Demo/getsurveyall").success(function(data) {
        $scope.surveys = data;
    });
});
控制器代码:

@RequestMapping(value = "/getsurveyall", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody String getSurveyAll() throws JsonProcessingException {
    Set<SurveyRecords> records = new HashSet<SurveyRecords>();
    records.addAll(surveyService.getSurveyAll());
    return new ObjectMapper().writeValueAsString(records);
}
@RequestMapping(value=“/getsurveyall”,method=RequestMethod.GET,products=MediaType.APPLICATION\u JSON\u value)
public@ResponseBody字符串getSurveyAll()引发JsonProcessingException{
Set records=newhashset();
addAll(surveyService.getSurveyAll());
返回新的ObjectMapper().writeValueAsString(记录);
}
错误消息:

已阻止跨源请求:同一源策略不允许读取 远程资源位于。(理由: CORS标头“访问控制允许来源”缺失)


通过在WebAPI的web.config文件中进行以下更改,可以解决此问题: 参考网址:


我最近问了一个问题,在这个问题中,我收到了有关春季CORS问题的详细信息,请阅读尼古拉回答:

你的应用程序的url是什么?实际上,我在基于spring hibernate的应用程序中有web.xml文件。请参阅以下链接:
   <system.webServer>
           <httpProtocol>
               <customHeaders>
                   <add name="Access-Control-Allow-Origin" value="*" />
               </customHeaders>
           </httpProtocol>
       </system.webServer>