【发布时间】:2017-07-13 19:00:49
【问题描述】:
我正在尝试做的事情:
I want to set up a server that processes GET requests and can be called from any domain.
None of the data is private so I want to enable CORS.
为什么?
I'm trying to teach people web development one step at a time.
Step 1 I want to teach people basic javascript and pulling data without them
needing to interact with the server side at all.
当前的基础设施:
I'm running a tomcat server in eclipse, with a few get requests coded in java.
I want users to be able to make get requests from their localhosts or
from any url just by typing in the chrome console. I currently can execute the
get requests from the same domain, but when I try from my localhost I get an error.
到目前为止我已经尝试过:
oh boy where to start:
1. upgrading tomcat, possible but would need to go through lots of bureaucracy
2. Updating the web.xml with a CORS filter.
Every time I do this it ends up failing to start the server
3. jsonp. This works to get the data looking in the network tab, but my success
function isn't being called, and research shows it's because I'm passing
a json object and the browser is expecting a jsonp. How can I do that from the
server?
4. Setting crossOrigin: true in the ajax request. That doesn't work and I still
get the same "no Access-control-allow-origin header is present..." error.
关于其他尝试的任何建议,或者关于为什么我尝试过的方法都没有奏效的详细信息?
谢谢。
【问题讨论】:
-
呃,我以为我很聪明地使用代码缩进并使它看起来更好,但是突出显示很糟糕:(
标签: javascript tomcat server cors