0

I have a JBOSS server running on port :8080 and a CherryPY server running on :8099

If I attempt to do the following

var insertObj = {
    poi_id : "12345",
    obv_id : ""
};

var url = "http://10.XX.X.XXXX:8099/output";

$.ajax({
    type : "GET",
    url : url,
    data : JSON.stringify(insertObj),       
    contentType : "application/json",
    dataType : "json",
    success : function(response) {
        alert(response);
    }
});

EDIT 1:

This is how I've set up my cherryPy server

class TestServer(object):
    @cherrypy.expose
    def index(self):
        return "Hello World!"

    @cherrypy.expose
    @cherrypy.tools.json_out()
    @cherrypy.tools.json_in()
    def test(self):
        print 'set up the response headers'
        cherrypy.response.headers["Access-Control-Allow-Origin"] = "http://localhost"
        cherrypy.response.headers["Allow"] = "POST, GET"
        input_json = cherrypy.request.json
        print input_json

def CORS(): 
    cherrypy.response.headers["Access-Control-Allow-Origin"] = "*" # mean: CORS to all; insert spec. origin to allow spec access 
    # ... insert further resp headers if needed 

if __name__ == '__main__':
    cherrypy.tools.CORS = cherrypy.Tool('before_handler', CORS)
    port = int(os.environ.get('PORT', 8099))
    cherrypy.config.update({'server.socket_host': '10.XX.X.XXX',
                        'server.socket_port': port,
                        'tools.CORS.on': True,
                       })
    cherrypy.quickstart(TestServer())

However, I still get the same issue in Chrome/Firefox/IE

XMLHttpRequest cannot load http://10.XX.X.XXX:8099/test. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://10.XX.X.XXX:8080' is therefore not allowed access. 
ist_lion
  • 3,149
  • 9
  • 43
  • 73
  • http://enable-cors.org/server.html – Ray Nicholus May 08 '14 at 17:08
  • Right, but I haven't seen anything in regards to CherryPy. My 8080 is the JBOSS server and that's the one calling the CherryPy server. – ist_lion May 08 '14 at 17:23
  • If CherryPy is the request handler, then you'll need to ensure it is returning proper CORS headers. Here's a gist that details how to handler CORS requests in python: https://gist.github.com/enjalot/2904124. If that doesn't work for you, googling "cors python" or "cors cherrypy" will likely provide many solutions. – Ray Nicholus May 08 '14 at 17:28
  • Similar question : http://stackoverflow.com/questions/19612319/cherrypy-jquery-cors-trouble – Ortomala Lokni Jul 27 '14 at 14:45

0 Answers0