1

I've gone through few posts and articles but it doesnt work for me. I am looking the working solution.

Problem:- $http.get making additional call i.e OPTIONS whenever i call my service.

Ex: website: http://locahost:4020/dashboard
Api: http://locahost:3020/filters

app.config(['$httpProvider', function ($httpProvider) {
$httpProvider.defaults.useXDomain = true delete $httpProvider.defaults.headers.common['X-Requested-With']
//$httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest' //Reset headers to avoid OPTIONS request
$httpProvider.defaults.headers.common = {}
$httpProvider.defaults.headers.post = {}
$httpProvider.defaults.headers.put = {}
$httpProvider.defaults.headers.patch = {}
$httpProvider.defaults.headers.get = {} } ])

$http.get(url + '?' + $.param(args || ''), req)

http://locahost:3020/filters is failing to return data whenever i call since OPTIONS call is going on before actually api call(get).

enter image description here

Rakesh Chand
  • 3,105
  • 1
  • 20
  • 41
Siva P
  • 109
  • 1
  • 12

1 Answers1

1

You can't discard preflight OPTIONS request.

The purpose of this request is to ask the server for permissions to make the actual request. Your preflight response needs to acknowledge these headers in order for the actual request to work.

See this answer

And these header are deprecated from angular so there is no point of putting them in.

headers to avoid OPTIONS request
$httpProvider.defaults.headers.common = {}
$httpProvider.defaults.headers.post = {}
$httpProvider.defaults.headers.put = {}
$httpProvider.defaults.headers.patch = {}
$httpProvider.defaults.headers.get = {} } ])
Community
  • 1
  • 1
Rakesh Chand
  • 3,105
  • 1
  • 20
  • 41
  • Appreciated your response rakesh. could you please guide me to resolve this. I am not getting response, have to make 2 requests each time to get data. When make request first time, not getting response and after 2 sec , making another request , getting response after 2 request. – Siva P May 18 '17 at 14:50
  • Aren't you getting response in 2nd request ? If not. What are you getting ? – Rakesh Chand May 19 '17 at 07:16
  • I am getting 2nd response as 500 instead of 200 besides request takes long time(2 min) to get the response back. request is failing alternatively i mean 1 request got response, 2 request failing, 3 request got response, 4th is failing(500)... – Siva P May 19 '17 at 13:48
  • This is API issue nothing to do with Frontend – Rakesh Chand May 19 '17 at 15:35