4

I used angluar4 http, Such as login request server, When I click the button to submit the form, Google Chrome's network to capture the two requests, one of which is zone.js: 2744 (the return of the data is wrong).

Why is there twice?

My code reference here: https://angular.cn/tutorial/toh-pt6

1 all 2 first 3 second

Peter
  • 10,492
  • 21
  • 82
  • 132
ChiakiYu
  • 905
  • 1
  • 8
  • 7

1 Answers1

6

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

You are seeing the OPTIONS call first - which is a call the browser does automatically (in certain conditions) when requesting data from a different origin (server) than what you served the html from.

PiniH
  • 1,901
  • 13
  • 20
  • Thank you. So should i handle the server side? – ChiakiYu Sep 19 '17 at 09:20
  • It's considered best practice to issue http calls to the same endpoint that serves the html files, there are serveral ways to do this: 1. Add an nginx layer that will redirect requests to either static files or the server. 2. Add file serving on your server. There are probably more, but that is the best approach. If you are using angular2 you have the webpack proxy option so you can call the same address and webpack will proxy it to your server. – PiniH Sep 19 '17 at 10:54