javascript - Using JavaEE - SSH framework to develop web projects, how to use CORS to implement cross-domain requests?
伊谢尔伦
伊谢尔伦 2017-06-12 09:23:02
0
1
731

1. I have configured it according to the CORS help document. The document path is: http://www.ruanyifeng.com/blo...;
Local project configuration is as shown in the figure: (1). Import support package
(2) Configuration of web.xml
2. Through the above configuration, in theory it is possible to make cross-domain requests, but in fact it is not possible! Paste my html code:

   axios - get example  

axios.get

    The url is Douban's api
    The running result is:
    The request header and the request status are:
    (1)General
    (2)Response
    (3)Request
    3. I am very confused. The request status code is 200, why is there no The data is returned and the console reports an error? The official document says that as long as it is configured, it can be used across domains. Why can't it be implemented on this machine? Is there something wrong with the configuration? Or is there something missing? Please give me some advice from relevant experts! I am a member of the Third Party of China. I urgently need to solve this problem when I am working on a project. Thank you very much!

    伊谢尔伦
    伊谢尔伦

    小伙看你根骨奇佳,潜力无限,来学PHP伐。

    reply all (1)
    为情所困

    There are many ways to solve cross-domain requests. The cors method relies on the server to return the correct response header informationAccess-Control-Allow-Origin. Your screenshot shows that the Douban api does not returnAccess-Control-Allow-Origin:*, so cross-domain failure.
    You can also use jsonp to solve cross-domain problems. Douban supports jsonp.


      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!