title: Responding to AJAX GET and POST requests with Google App Engine (Python)
body: <p>I have confusion on how the servers(here app engine) respond to AJAX GET and POST requests. I want send a GET request to my server and get some JSON data back.</p>
  
  <p>Here is the AJAX GET request</p>
  
  <pre><code>function syncRestoreLinks(e) {
  
      var request = new XMLHttpRequest();
      var url = "/sync"
  
      request.open("GET", url);
      request.setRequestHeader("Content-Type", "application/json");
  
      request.onreadystatechange = function() {
      if (request.readyState === 4) {
          console.log(request.responseText);
          }
      }
      request.send(null);
      console.log("Getting links from db");
  }
  </code></pre>
  
  <p>Handler on the server side</p>
  
  <pre><code>class SyncHandler(Handler):
      def get(self):
          response_data = {"loggedIn":False, "linkData":None, "success":False}
          json_txt = json.dumps(response_data)
          self.response.headers['Content-Type'] = 'application/json; charset=UTF-8'
          self.response.out.write(json_txt)
  
      def post(self):
          response_data = {"loggedIn":False, "linkData":None, "success":False}
          json_txt = json.dumps(response_data)
          self.response.headers['Content-Type'] = 'application/json; charset=UTF-8'
          self.response.out.write(json_txt)
  </code></pre>
  
  <p>This handler writes my response data out to the screen where as I want it to send it back and let JS handle it. (I am able to use server redirects here.)</p>
  
  <p>If I make a POST request instead, the code works the way I intend it to. But here, I cannot make server redirects or render pages and only the script making request has that control.</p>
  
  <p>Is this how GET/POST responses work or I am doing something stupid in my code?</p>
  
  <p>Is there any way for GET response not to be written on the page and be sent to JS? In the code above the responseText is an empty string but, the json is printed on screen.</p>