解决报错
XMLHttpRequest cannot load http://192.168.31.151/smartcity/add.PHP. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:8156’ is therefore not allowed access.
在 Servlet 的头部加上
response.setHeader(“Access-Control-Allow-Origin”, “*”);
如果你不想所有请求到此 Servlet 的 request 都通过 , 可以改为
response.setHeader(“Access-Control-Allow-Origin”, “yoururl”);