No 'Access-Control-Allow-Origin' header is present on the requested resource.

Please indicate the source for the original reprint: http://agilestyle.iteye.com/blog/2353274

 

Usually in project development, we usually encounter cross-domain calls, and then we encounter this error when requesting a call

No 'Access-Control-Allow-Origin' header is present on the requested resource.


 

There are usually two workarounds to resolve this error

1. JSONP

2. CORS

Note: 

Compared with JSONP, CORS is more advanced, convenient and reliable.

  • JSONP can only implement GET requests, while CORS supports all types of HTTP requests.
  • With CORS, developers can use normal XMLHttpRequest to make requests and get data, with better error handling than JSONP.
  • JSONP is mainly supported by older browsers, which often do not support CORS, while most modern browsers already support CORS.

However, now your project is still in the development stage, such as the technology selection POC stage, there is no need to make it so complicated, so the easiest way is to install a plugin Allow-Control-Allow-Origin in Chrome, which can be fast and effective. to solve such problems.


 

After installation


Turn on CORS, debug the cross-domain call again, and the error is gone


 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326992423&siteId=291194637