无法使用jquerymobile在workligh应用程序中的url中发送数组

时间:2014-01-28 11:04:07

标签: jquery-mobile ibm-mobilefirst

我正在使用jquerymobile在IBM worklight中构建混合应用程序。 我想将服务器php返回的json数组发送到url中的另一个页面。代码如下所示:
searchPools.js文件 (调用另一个页面的文件)

$(document).undelegate('#srhPool', 'click').delegate('#srhPool', 'click', function() {
                    var source = $("#csource1").val();
                    var destination = $("#cdest1").val();
                    var poolDate = $("#pooldate1").val();

                    if(source == null || source == "")
                        $("#csource1").parent().css('border','2px solid red');
                    if(destination == null || destination == "")
                        $("#cdest1").parent().css('border','2px solid red');
                    if(poolDate == null || poolDate == "")
                        $("#pooldate1").parent().css('border','2px solid red');


                    if(source == null || source == "" || destination == null || destination == "" || poolDate == null || poolDate == "" || validateRadio == false){
                        alert("Oops! Your Pooling Info is Incomplete.");
                    }
                    else{
                        savePool(userId, source, destination, poolDate, preferVehicle);
                    }
                });

            //save pool info

               function savePool(userId, source, destination, poolDate, preferVehicle){
                   $.mobile.utils.showWaitBox("a", "Wait! Searching Poolers...");
                    var invocationData9 = {
                            adapter : 'registerUser',
                            procedure : 'searchPoolData',
                            parameters : [userId, source, destination, poolDate, preferVehicle]
                    };

                    WL.Client.invokeProcedure(invocationData9, {
                        onSuccess : poolSuccess,
                        onFailure : poolFailure,
                    });
                }

                function poolSuccess(result){
                    $.mobile.utils.hideWaitBox();
                    var invocationResult = result.invocationResult;
                    var array1 = invocationResult.pools;
                    var dataurl2 = '?array='+array1;

                    $.mobile.changePage('../../pages/passenger/poolResults.html'+dataurl2, {transition: "slide"});

                }

                function poolFailure(result){
                    $.mobile.utils.hideWaitBox();
                    WL.Logger.error('Search Unsuccessful');
                }

poolResults.js (访问数组的文件)

$(document).on( 'pagebeforeshow', '#poolResults', function(event){

    var params = new Array();

     function getParams(){
             var idx = document.URL.indexOf('?');

             if (idx != -1) {
             var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
             for (var i=0; i<pairs.length; i++){
             nameVal = pairs[i].split('=');
             params[nameVal[0]] = nameVal[1];
             }
             }
             return params;
         }
         params = getParams();
         getArray = unescape(params["array"]);
         alert(getArray);
});

它无法正常工作。
我想要做的是点击页面中的按钮,然后通过http适配器检索一些结果。在searchPools.js文件中,在poolSuccess函数中成功获取了值。现在,这些值将显示在使用$ .mobile.changePage显示的另一页上。
我想知道我使用的方式是对的,或者其他方式可用于实现此目的。

1 个答案:

答案 0 :(得分:1)

像这样发送数组

$.mobile.changePage('page2.html', { dataUrl : "page2.html?parameter=123", data : { 'paremeter' : '123' }, reloadPage : true, changeHash : true });

并像

一样检索它们
$("#index").live('pagebeforeshow', function (event, data) {
    var parameters = $(this).data("url").split("?")[1];;
    parameter = parameters.replace("parameter=","");  
    alert(parameter);    
});

For More Info See The Link

为了您的理解将其传递给

$.mobile.changePage("newPage.html", {data:{ param1 : YOUR JSON } });

并将其检索为

    <script type="text/javascript">
        $("#newPageId").on("pageshow", onPageShow);

        function onPageShow(e,data)
        {
            var url = $.url(document.location);

            var param1 = url.param("param1");
        }
    </script>