0

send ajax to tornado server for redirection and get 200 status code. client side

 $.ajax({
                    type: "POST",
                    url: url,
                    processData: false,
                    contentType: 'application/json',
                    data: data,
                    complete: function (xmlHttp, textStatus) {
                        alert(xmlHttp.status.toString());
                        alert(textStatus);
                        if (xmlHttp.status.toString()[0] == '3') {
                            top.location.href = xmlHttp.getResponseHeader('Location');
                            alert(top.location.href)
                        }
                    }
                });

server side

class Login(tornado.web.RequestHandler):
    def post(self):
    print "post"
    print self.request.body
    self.redirect("/")

on chrome browser F12 network tag

login            post 302 ...
10.xxx.xxx.xxx   get  304 ...

why the alert function display 200 status code? Thanks

cppython
  • 1,209
  • 3
  • 20
  • 30
  • 1
    jQuery "automatically" follow redirects when doing AJAX requests, so you don't get to "see" the redirect on the client. Related: http://stackoverflow.com/questions/9177252/detecting-a-redirect-in-jquery-ajax – alexander.biskop Mar 24 '15 at 18:16
  • if that, what is the best way to implement my ideal? I want to redirect to another page if server send me a redirection code – cppython Mar 24 '15 at 18:34
  • So you want to redirect to a page *different* from that that the server redirects you to? – alexander.biskop Mar 25 '15 at 11:32

0 Answers0