6

enter image description hereI run the axios get method to call php script.but request send twice how to solve this problem. myfunction:-

   axios.get('http://13.233.179.174/customers_log.php',{
                  headers: {
                    'Access-Control-Allow-Origin': '*'
                  },
                })
                  .then(function (response) {
                    $("#spinner").hide();
                    console.log('this is response work');
                    console.log(response.data);
                  })
                  .catch(function (error) {
                    $("#spinner").hide();
                    console.log(error);
                  })
ShrJoshi
  • 325
  • 1
  • 6
  • 13
  • Are you calling your function twice? – GasKa Apr 24 '19 at 05:45
  • No but on console it show twice i am adding the picture please check. – ShrJoshi Apr 24 '19 at 05:52
  • `Access-Control-Allow-Origin` is a **response** header. It does not go in your request – Phil Apr 24 '19 at 05:55
  • Possible duplicate of [How does Access-Control-Allow-Origin header work?](https://stackoverflow.com/questions/10636611/how-does-access-control-allow-origin-header-work) – Phil Apr 24 '19 at 05:56
  • If the first request method is not Options, but Get also, check your event handler. Probably, you have to add something like @click.once – Manu Apr 24 '19 at 06:52

1 Answers1

6

It'a Preflight request

It is an OPTIONS request, using three HTTP request headers: Access-Control-Request-Method, Access-Control-Request-Headers, and the Origin header.

Check here - https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request

arora
  • 869
  • 7
  • 12