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.
Jquery:
$.ajax({
type:"post",
url: "/newform",
data:$('#my-form').serialize(),
success: function(msg){
alert(msg);
},
error: function(msg){
alert(msg);
}
});
Python 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})