Access-Control-Allow-Headers不允许我的代码显示Access-Control-Allow-Origin的错误

时间:2014-02-28 04:56:01

标签: angularjs http-headers

这是我的代码我正在使用它显示Access-Control-Allow-Origin的错误是Access-Control-Allow-Origin不允许的,但它正确地在REST客户端上工作

$scope.addTodo = function() {

    var url = 'http://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive/Find/v1.10/json2.ws?Key=XE97-xXxx-YG99-JK92&SearchTerm=12345&PreferredLanguage=English&Filter=&UserName=&CallbackFunction=a';
    var config1 = {headers:{
    'Access-Control-Allow-Origin':'*',
    'Access-Control-Allow-Methods': ['OPTIONS', 'GET', 'POST'],
    'Access-Control-Allow-Headers':'Origin, X-Requested-With, Content-Type, Accept',
    'Content-Type':'text/plain; charset=utf-8',
    'Accept':'*/*'
            }};
     //Enable cross domain calls
        $http.defaults.useXDomain = true;

        //Remove the header used to identify ajax call  that would prevent CORS from working
        delete $http.defaults.headers.common['X-Requested-With'];



    $http.get(url, config1). 
success(function (data, status, headers, config) {
  alert("success");
  if(data.success){
  alert("inside success");
  }else{
 alert("inside else");
  }
}).
error(function (data, status, headers, config) {
  alert("Error, please report to admin. Error code is " + status);


});

    };

0 个答案:

没有答案