top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

How can I resolve Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers, error

+1 vote
1,010 views
$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':'*/*'
            }};
   //  alert("hello");
   alert("url" + url);
   //Enable cross domain calls
   $http.defaults.useXDomain = true;
   // alert("$http.defaults.useXDomain");
   //Remove the header used to identify ajax call  that would prevent CORS from working
   delete $http.defaults.headers.common['X-Requested-With'];
    //   alert("$http.defaults.headers.common");
    //  alert("$http.config1"+config1);
    //  alert("url" + url);

    $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);
//alert("data, please report to admin. Error code is " + data);      
});
};
posted Feb 28, 2014 by anonymous

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button
Please put more details like which language, what you have tried, what you are expecting, what is the error. The problem is having just some code and one statement, I can not make out anything from this...Please put necessary info so that people can help...

Similar Questions
+1 vote

I have the following code to add the appropriate header then redirect but I am still getting an error that this header is missing. What am I doing wrong?

 header("HTTP/1.1 301 Moved Permanently");
 header("Access-Control-Allow-Origin: http://".$_SERVER['HTTP_HOST']);
 $augmentedUrl = $playbackbase."?authTicket=$authTicket";
 header("Location: $augmentedUrl");
+2 votes

I want the images should be accessible as part of http page only not by any other mean, no clue any suggestion would have great help.

+2 votes

I have task to validate or parse following http header

Accept
Accept-Charset
Accept-Encoding
Accept-Language
Accept-Datetime
Content-Length
Content-MD5
Content-Type

lets take Accept-Language as an example , if header language comes other than en-us I should reject the request with customized code response.

let me know ways to achieve the task? can we do with any configuration files?
We are using tomcat 6.0.18

+1 vote

1) I'd have a question on how to set up a reverse proxy to a http 1.0 in the cleanest most standard conforming way.

AFAIU, strict HTTP 1.0 has neither persistent connections / keep-alives
- a connection ends after a single request has been responded. Neither does it have Host: headers.

a) Do I need to tell the reverse-proxy about this? Do I have to set:
- ProxyPass' disablereuse=on and/or
- force-proxy-request-1.0 and/or
- proxy-nokeepalive and/or
- proxy-sendcl

Or is one of them enough? E.g. when I set force-proxy-request-1.0... all the others are implicitly set?

b) Do I need to set proxy-initial-not-pooled?
Cause I get the error mentioned there,... interestingly that seems to be independent of the backend/origin server... and dependent on the client.

c) So, strictly speaking, I could not use name-based vhosting, right?

2) Further, when a client talks to the reverse proxy in HTTP 1.0 it should get the reply in 1.0 either. And when it talk to it in 1.1, it should get it in 1.1.

Would Apache do this automatically, or would it answer a 1.0 request with a 1.1 response?
So do I have to set: force-response-1.0 ?

3) The origin server to which I connect is single threaded, i.e. it will only process one request at a time. So Apache shouldn't connect more than once concurrently, as it would simply block. How do I get this? The keep-alive options above probably don't help here... Is the solution to set ProxyPass' max=1 ?

+2 votes

I am getting this there while updating Sub module in my main project

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...