nobodaddy
nobodaddy

Reputation: 21

jQuery AJAX/Tornado method not responding

I've been working on a project on Tornado and just started integrating a few AJAX calls via jQuery. I'm pretty new to all of this so forgive me if there's an obvious answer.

I have an AJAX call set up to submit a login form. This calls the appropriate Tornado handler and I can see it working up until the point that it is supposed to render a new page, at which point it simply does not render the page. I see the logging message right before the render call and then nothing. No errors, it just stays on the same page and does nothing. Anyone have any idea what's up? Many thanks for any help.

Here's the snippet from the Python:

if auth:
            self.set_current_user(username)
            logging.info("LOGGED IN: RENDERING HOME")
            self.render("home.html") 

On the jQuery side, it's very simple too:

$(document).ready(function(){
    $("form#loginform").submit(function(){
        console.log("submitting form");
        $.post("/login",{
                    email: $("#email").val(),
                    password: $("#password").val(),
                    action: "postmsg"
                }, function(xml) {
            $("#msg").empty();
            returnCall(xml);
        });
        return false;
    });
});
function returnCall(xml) {
    console.log("returned");

}

Upvotes: 1

Views: 830

Answers (1)

nobodaddy
nobodaddy

Reputation: 21

Eventually I found the answer to this through a friend and am just putting it here for future travelers. Apparently if you call to render pages via AJAX, the page you want rendered just gets loaded into memory, but not actually rendered in the browser. If I do a trace of "xml" in the example provided, it returns the unrendered text of the HTML document I wanted to display.

In this case, I have to do some kind of callback to the Javascript to let it know that the user is either authorized or not on the python end, and then use that to redirect to a page from the javascript.

Hope that helps someone.

Upvotes: 1

Related Questions