Skip to content Skip to sidebar Skip to footer

JQuery Mobile Retrieving Data Between Pages

I'm using jquery mobile in a phonegap application and I'm trying to pass a variable from a textbox in to the next page to do an xml traverse with the variable. My page has this jav

Solution 1:

The ssname.html file will have to be parsed by a server-side language to get the POST variables. You can however access GET variables from JavaScript:

$("#s-sur").live('pageinit', function() {
    $("#search").click(function() { 
        $.mobile.changePage( "ssname.html", {
            type : "get",
            data : $("#search").serialize()
        });
    });
});

and then for the ssname.html page:

$("#ssname").live('pageinit', function() {
    //now you can get your variables from the URL: location.search
});

You could also just use a global variable to hold the information between pages:

$("#s-sur").live('pageinit', function() {
    $("#search").click(function() {
        window.myCustomVariable = $("#search").serialize();
        $.mobile.changePage("ssname.html");
    });
});

Then on the ssname.html page you can just read the window.myCustomVariable variable to do work. This works because the pages will occur in the same DOM, so the window.myCustomVariable variable will exist for both pages.


Post a Comment for "JQuery Mobile Retrieving Data Between Pages"