location /api/user{
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE;
#add_header Access-Control-Allow-Headers 'authorization';
default_type application/json;
#return 200 '{"id":1,"name":"TOM","age":18}';
把return 200 '{"id":1,"name":"TOM","age":18}'; 这句注释掉,运行网页就会出现下面的错误:
Access to XMLHttpRequest at 'http://127.0.0.1/api/user' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
c.html:63 Error: undefined
error @ c.html:63
c @ jquery-3.6.0.min.js:2
fireWith @ jquery-3.6.0.min.js:2
l @ jquery-3.6.0.min.js:2
(anonymous) @ jquery-3.6.0.min.js:2
error (async)
send @ jquery-3.6.0.min.js:2
ajax @ jquery-3.6.0.min.js:2
(anonymous) @ c.html:54
dispatch @ jquery-3.6.0.min.js:2
v.handle @ jquery-3.6.0.min.js:2
jquery-3.6.0.min.js:2