jQuery mobile retrieving data between pages

不打扰是莪最后的温柔 提交于 2019-12-11 19:51:20

问题


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 javascript to send the variable through but I don't know how to retrieve it on the next page.

<script type="text/javascript">
    $("#s-sur").live('pageinit', function() {

            $("#search").click(function() { 
                 $.mobile.changePage( "ssname.html", {
                type: "post",
                data: $("#search").serialize()
                                                        });
            });

    });
</script>

回答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.



来源:https://stackoverflow.com/questions/10502558/jquery-mobile-retrieving-data-between-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!