Page hangs on Ajax request to GAE
<p>I've created a page that interacts with an app written with Python on GAE, to return JSON data (via JSONP, because Cross-origin stuff). However, no matter what method I use, the page always hangs and data never actually makes it to the screen. It runs just fine if I request the stuff by typing the appspot URL into my address bar, though.</p>

<p>Here's the main part of le code.</p>

<p>Python main.py (on GAE)</p>

<pre><code>def retrieve_data(self):
    # Retrieve data from some API, manipulate and return result.

# Note: I'm not using this handler for the request.
# It's just there in case I need it.
class MainHandler(webapp2.RequestHandler):
    def get(self):
        data = retrieve_data(self)
        self.response.headers["Content-Type"] = "application/json"
        self.response.out.write(
            json.dumps(data)
        )

# I'm using this handler for the JSONP request.
class JSONPHandler(webapp2.RequestHandler):
    def get(self):
        data = retrieve_data(self)
        self.response.headers["Content-Type"] = "application/json"
        self.response.out.write(
            "%s(%s)" %
            (urllib2.unquote(self.request.get("callback")),
            json.dumps(data))
        )

app = webapp2.WSGIApplication([
    ('/', MainHandler),
    ('/jsonp', JSONPHandler)
], debug=True)
</code></pre>

<p>index.js (Not hosted on GAE)</p>

<pre><code>function add(data) {
    // Sort data, add to DOM.
}

$.ajax({
    type: "GET",
    dataType: "jsonp",
    url: "(APPSPOT URL)/jsonp",
    success: function(data) { add(data) }
});
</code></pre>

<p>I've also tried $.get, creating a script tag with a src pointing to the appspot link, and other XMLHTTPRequest methods people described, but none seem to work.
If I tell success to just console.log the data, it will do so after a few seconds of running.</p>

<p>So, is there something wrong with the code? Am I missing something in main.py, or am I AJAXing it wrong?</p>

<p>I used this code to receive cross-origin json request POST data in my webapp2 handler:</p>

<pre><code>def options(self):
    self.response.headers['Access-Control-Allow-Origin'] = '*'
    self.response.headers['Access-Control-Allow-Headers'] = '*'
    self.response.headers['Access-Control-Allow-Methods'] = 'POST, OPTIONS'

def post(self):

    self.response.headers['Access-Control-Allow-Origin'] = '*'
    self.response.headers['Access-Control-Allow-Headers'] = '*'
    self.response.headers['Access-Control-Allow-Methods'] = 'POST, OPTIONS'

    data = self.request.body
    args = json.loads(data)
</code></pre>

javascript jquery python ajax google-app-engine