-1

I'am sure it execute controllers once, but execute $http request twice.So every operation to my DB does twice!

The requests cross domain,and I set 'Access-Control-Allow-Origin:*'.

I get OPTIONS request before every normal request,but I guess the OPTIONS request have nothing to do with the TWICE problem.

Request screenshot

CoderPi
  • 11,946
  • 4
  • 28
  • 58
markjiang
  • 397
  • 1
  • 2
  • 12

1 Answers1

1

This is preflight CORS requests. Notice that first request is OPTIONS and second one is POST.

This happens when you send request to other domain

Very good explanation: CORS - What is the motivation behind introducing preflight requests?

Community
  • 1
  • 1
suvroc
  • 2,938
  • 1
  • 12
  • 28
  • What bothers me is that every request oprates DB twice,will preflight infect DB?How can I solve the problem? – markjiang Jan 04 '16 at 13:05
  • 2
    Depending to your API. But generally you shouldn't touch DB in OPTIONS requests – suvroc Jan 04 '16 at 13:14
  • I haven't touch DB in my OPTIONS request,actually I don't know how to oprate OPTIONS request. – markjiang Jan 04 '16 at 13:30
  • Man,thanks for your patience.The backend language is PHP – markjiang Jan 04 '16 at 13:41
  • It's not my language so just try to debug what is the HTTP context during this first API method execution. Or after your investigation make another question related to your PHP API – suvroc Jan 04 '16 at 13:45
  • I don't if I have express my situation clearly.My request call API that oprates DB,but I haven't do anytiing with the OPTIONS request,so I think it won't oprate DB. – markjiang Jan 04 '16 at 13:48