title: returning ajax error from python to jquery
body: <p>I am doing an AJAX form post in jQuery. However, when I return an error code from my Python server,it's being read as success instead of as error. My code is below. I am a noob in Python. So apologize if I am making obvious mistakes.</p>
  
  <p>Jquery:</p>
  
  <pre><code> $.ajax({
  
                  type:"post",
                  url: "/newform",
                  data:$('#my-form').serialize(),
                  success: function(msg){
  
                      alert(msg);
  
  
                  },
                  error: function(msg){
  
                       alert(msg);
                  }
              });
  </code></pre>
  
  <p>Python code:</p>
  
  <pre><code>def post(self):
  
      email = self.get_secure_cookie("user")
      id_name = self.get_argument('id1', None)
  
      try:
          credentials = Credentials(email=email, id_name=id_name)
          credentials.save()
  
      except Exception, e:
          print '%s' % str(e)
          msg = 'Authorization Failed. Please check if the credentials are correct'
          status = "error"
  
      else:
          msg = 'Connected'
          status = "success"
  
      print 'status: %s' % status
      self.write({"status": status, "msg": msg})
  </code></pre>