繁体   English   中英

jQuery mobile检索页面之间的数据

[英]jQuery mobile retrieving data between pages

我在phonegap应用程序中使用jquery mobile,并且试图将文本框中的变量传递到下一页,以对该变量进行xml遍历。

我的页面上有此JavaScript,可以通过它发送变量,但我不知道如何在下一页上检索它。

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

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

    });
</script>

ssname.html文件将必须由服务器端语言解析以获取POST变量。 但是,您可以从JavaScript访问GET变量:

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

然后进入ssname.html页面:

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

您也可以只使用全局变量来保存页面之间的信息:

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

然后,在ssname.html页面上,您只需阅读window.myCustomVariable变量即可工作。 之所以window.myCustomVariable ,是因为页面将出现在同一DOM中,因此两个页面都将存在window.myCustomVariable变量。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM