Enable CORS AngularJS to send HTTP POST request

后端 未结 5 982
眼角桃花
眼角桃花 2020-12-10 02:33

I want to send an HTTP POST request by submitting a form to my server, which is located at a different domain (enabled cors in the server script using node.js).

Thi

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-10 03:03

    You just have to add some header properties in your server side response header.

    Here is an example for NodeJS server

    app.all("/api/*", function (req, res, next) {
      res.header("Access-Control-Allow-Origin", "*");
      res.header("Access-Control-Allow-Headers", "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With");
      res.header("Access-Control-Allow-Methods", "GET, PUT, POST");
      return next();
    });
    

    It will solve AngularJS cross-domain AJAX call.

    I have found this solution from How to enable CORS in AngularJs

提交回复
热议问题