1

I have a GAE app which accepts JSON requests and replies with JSON in the response. I know it works as I have an Android app that works with it. I'm trying to set up a JavaScript browser based interface as well. To do this I'm trying to send a request via JQuery from a page hosted on a different GAE domain. However, as far as I can see the ajax is not sent at all.

<!DOCTYPE html>
<html>
<head>
<script>
    function loadXMLDoc() {

        alert("before ajax.....");

            $.ajax({
                  type: "POST",
                  url: "CORRECT URL HERE",
                  data: {
                      type:"GAMES_LIST"
                  },
                  jsonpCallback: function(){
                      alert("success");
                  },
                  async: false,
                  crossDomain : true,
                  dataType: 'jsonp'
                });


            alert("after ajax...");

    }


</script>
</head>
<body onLoad="loadXMLDoc()">

    <div id="myDiv"></div>

</body>
</html>

Only the first 'before ajax' alert is fired.

Has anyone got an idea what I'm doing wrong?

yedidyak
  • 1,964
  • 13
  • 26
  • 1
    Have you checked your browser debug tools (especially the network section)? It can provide some hint. – CaptainPatate Apr 01 '14 at 12:16
  • I think Peter Hudec is right. Apparently there is no way to use jsonp with POST requests, only GET. Does anyone know how to configure GAE with CORS to bypass the Same-origin policy? – yedidyak Apr 01 '14 at 13:54
  • @yedidyak, yes, jsonp won't work with POST requests. Here is why: http://stackoverflow.com/questions/2699277/post-data-to-jsonp – Peter Hudec Apr 01 '14 at 15:03

1 Answers1

1

By making an AJAX request to a different domain, you are violating the Same-origin policy.

If you have access to the JSON endpoint, you can allow specific domains to access your endpoint in the Access-Control-Allow-Origin HTTP header.

If you don't have access to the endpoint e.g. it's a third-party provider, you can make a JSONP request if the provider supports it.

Peter Hudec
  • 2,462
  • 3
  • 22
  • 29