Search code examples
javascriptxmlhttprequestcherrypy

Ajax calls to subdomain


I have one server located at example.com running apache, serving my static html files.

I also have a json service located at api.example.com running python with cherrypy.

The user requests example.com and get the index html page. On that page I make an ajax request with jquery to the json service. document.domain returns example.com

        $.ajax({
        type: 'GET',
        url: 'http://api.example.com/resource/',
        dataType: 'json',
        success: successCallback,
        error: errorHandler
    });

However, I can't see the response body for the ajax request in firebug. This leads me to believe that the browser (FF) doesn't support this.

What are the best methods to achieve this? I would prefer not to use any proxying on the apache backend for example.com if possible.


Solution

  • You can also use JSONP by adding callback=? to the end of the url. jQuery already knows how to handle these type of requests but it does require some server side changes to handle the callback param.