jQuery mobile检索页面之间的数据 [英] jQuery mobile retrieving data between pages

查看:83
本文介绍了jQuery mobile检索页面之间的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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>

推荐答案

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

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()
        });
    });
});

,然后进入ssname.html页面:

$("#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");
    });
});

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

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.

这篇关于jQuery mobile检索页面之间的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆