3

I am getting below error in Angularjs

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://.../... (Reason: CORS header 'Access-Control-Allow-Origin' missing).

below is my code:

     $http({
              method: 'GET',
              url:"https://logis../oms/rest/TMS/../listTenders/1.0",

              headers: { 'Authorization': 'Basic Q2FycmllckFUcmFuc01ncjpwYXNzd29yZA=='}
            }).success(function (response) {
                console.log("response--"+response);
              resolve(response);
            }).error(function (error) {
                console.log("error123--"+error)
              reject(error);
            });

I am using GET request in AngularJs and getting above error. So can any one help me if any thing is missing from client side or any thing is remaining from Server Side Server side is written in Java So please help me out. Thanks

pareshm
  • 4,874
  • 5
  • 35
  • 53
  • May be this my old question will help you: http://stackoverflow.com/questions/21455045/angularjs-http-cors-and-http-authentication – Georgi Naumov Dec 28 '15 at 11:41

2 Answers2

1

I got the same error.. Try calling the url from ur server side language (PHP or NOde)... Youll always get CORS error if u use a client side language(angular or normal AJAX) to call it.

Satyam S
  • 267
  • 3
  • 18
  • if i use POSTMAN the tool in chrome then i am getting the reponse – pareshm Dec 28 '15 at 11:36
  • There is no way to solve CORS on client side until you can control the response you are getting of the request. – Satyam S Dec 28 '15 at 11:42
  • So if the server to which u are making request has CORS unblocked, you wont get a error. But if it is not you will always get an error – Satyam S Dec 28 '15 at 11:44
  • JSONP will only work if you resonse is in JSONP format. This is not always true that response is in JSONP – Satyam S Dec 28 '15 at 11:44
  • means if CORS are set properly on Server side then i will not get error Access-Control-Allow-Origin: * if above header is set on Server side then i will not get error? – pareshm Dec 28 '15 at 12:23
  • if i am using php i am getting Response. But i don't have to use any server side language i just want use HTML to fetch the response and send the response – pareshm Dec 29 '15 at 05:48
  • PHP is a server side language – Satyam S Dec 29 '15 at 11:47
0

There are two ways for making cross origin requests. 1) Your server is configured to allow such requests 2) Using JSONP from jquery/javascript, For more detailed examples, see below link: https://learn.jquery.com/ajax/working-with-jsonp/

Jerry
  • 61
  • 3
  • can you help me in writing jsonp syntax for GET request i hav made above coz i tried but i am unable to use the JSONP for my GET request – pareshm Dec 29 '15 at 05:52