search

Home  >  Q&A  >  body text

Cross domain issue Access-Control-Allow-Origin - Stack Overflow

I have processed the header here, why is there still a cross-domain problem

PHP中文网PHP中文网2805 days ago852

reply all(5)I'll reply

  • PHP中文网

    PHP中文网2017-05-19 10:22:18

    I can’t see the picture clearly. Is this written in nodejs?

    reply
    0
  • 为情所困

    为情所困2017-05-19 10:22:18

    reply
    0
  • 为情所困

    为情所困2017-05-19 10:22:18

    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By",' 3.2.1')
    res.header("Content-Type", "application/json;charset=utf-8");

    node跨域 请参考

    reply
    0
  • PHPz

    PHPz2017-05-19 10:22:18

    Are you using express framework? This is how my express framework program works:

    app.all('*', function(req, res, next) {
      res.append('Access-Control-Allow-Origin', '*');
      next()
    });

    You need to process all requests in a unified manner and set the res header to allow cross-domain requests. I don’t know how to write your code specifically. If you still can’t solve it, I suggest you post the code and take a look.

    reply
    0
  • 某草草

    某草草2017-05-19 10:22:18

    Just use jsonp to cross domain

    getJSONDATA(){
                    $.ajax({
                        url: "xxx", //接口地址
                        data: {xxx}, //传参
                        dataType: "jsonp",
                        jsonpCallback: "person",  //核心cb
                        success: function (data) {
                            console.log(data.s);
                        }
                    });
                },

    reply
    0
  • Cancelreply