Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Page needs refresh after redirection from server

Page needs refresh after redirection from server


New question, but really close to need to refresh page in jquery mobile.

I have a /login page, to which user is redirected when accessing the / of the app for the first time (therefore not logged). BTW, to Login, user has only to provide a username. This /login page offers a form with a single text input, as follows:

Votre pseudo:

There is no action attribute on the form, therefore (unless I'm missing some fundamentals, hope not) the form submits with post to /login.

I'm using NodeJS with express, and handling the post request Server side looks like this:"/login", function (req, res) {
    //do some stuff, store username for instance...

I am indeed redirected to the / matching page (index), but embedded scripts in this index page are not run, and some jquerymobile objects are not fully operational: this index file has 2 JQM page (two divs with data-role="page"), and the footer of the first JQM page(div) has 2 links, with one pointing to the second page(div) (via anchors, JQM way). But this link isn't active either.

I do have to reload the / page in order to have the embeded scripts run ($(document).ready, scripts in header...) and all JQM objects responding correctly.

HINT: before reloading the page, in firebug, the the post /login request's response has a 302 statut (is it due to the Redirect Instructions Server side), and the following get / request (sure due to the redirect instructions server side) has an EMPTY response with a 200 statut, although it could load the page and the single image it embeds.

I'm surely missing something but can't figure out... thanks for all your help

Problem courtesy of: wiill


JQuery mobile uses ajax to load the requested page into the dom. The page you are requesting should only have one jqm "page" on it.

As I remember, I had to add all my scripts to my first page, and then bind to the page change event to decide when to execute them. I don't think jqm will execute the scripts in the page that was loaded via ajax.

Take a look at the page structure here:

More details in how the navigation works is here:

Solution courtesy of: Jonathan


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Page needs refresh after redirection from server


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription