Jquery移动传递params URL

时间:2016-06-07 16:30:25

标签: android jquery jquery-mobile

我正在尝试我的应用程序传递URL中的参数,我试图这样做,它在用户登录时很有效,但在用户注销时却不行。看看你是否可以帮助我。

此代码获取URL的参数,并根据参数显示事件或组织。

$(document).bind("pagebeforechange", function(event) { 
        hash=window.location.href;
        hashsplit=hash.split("?");

        if (hashsplit[1]!=undefined){
            hashsplit2=hashsplit[1].split("=");

            if (hashsplit2.length>0){
                code=hashsplit2[1];
                evento=hashsplit2[0];

                if (local_stor.user && local_stor.password){
                    if (evento=="organizationcode"){
                        getOrganization(code,"");
                        contpagebefore++;
                        event.preventDefault();
                        event.stopPropagation();
                    }

                    if (evento=="eventcode"){
                        getEvent(code,"");
                        contpagebefore++;
                        event.preventDefault();
                        event.stopPropagation();

                    }               


                }else{

                var cookie=JSON.parse(localStorage.getItem("event"));
                    if (cookie==null){
                        var events=[];
                            events[0]=evento;
                            events[1]=code;
                            localStorage.setItem("event", JSON.stringify(events));
                            $.mobile.changePage("#login");
                            event.preventDefault();


                    }

                }
            }
        }


});

当从带参数的链接访问webApp时,我收集这些参数,如果用户被记录,我会根据其中一个参数调用函数getOrganization或getEvent,如果用户未登录则将代码保存在localStorage中并更改要登录的页面。

当用户登录检查localStorage中的变量时,如果是,则使用我们在localStorage中保存的代码调用getOrganization或getEvent这两个函数中的一个。

函数getOrganization的代码:

function getOrganization(organizationcode,organizationname){
if (local_stor.user && local_stor.password) {
    $.mobile.loading("show");
    var organizationDetailRequest = getOrganizationDetailRequest(localStorage.user, localStorage.password,organizationcode);
    callWebServiceAsync(URL_API_KERNEL, organizationDetailRequest, successOrganizationDetail);


}else{
    $.mobile.changePage("#nologinMsg");
}

function successOrganizationDetail(data, textStatus, jqXHR){
    if (localStorage.event){
        localStorage.removeItem("event");
    }   
    var name="", code="",image="", city="", address="", captionImage="", description="",owner="",member="",contactPerson="", contactEmail="", contactPhone="", contactFax="";
    if ($(data).find("OrganizationDetailRequestResult")) {
        name = $(data).find("Name").text();
        code = $(data).find("Code").text();
        image = $(data).find("Image").text();  
        city = $(data).find("City").text();
        address = $(data).find("Address").text();
        captionImage = $(data).find("CaptionImage").text();
        description = $(data).find("Description").text();
        owner = $(data).find("TheUserIsOwner").text();
        contactPerson=$(data).find("ContactPerson").text();
        contactEmail=$(data).find("ContactEMail").text();
        contactPhone=$(data).find("ContactPhone").text();
        contactFax=$(data).find("ContactFax").text();

        if (contactPerson!=""){

            $("#contactPerson").html("<img class='iconevent' src='img/mi_cuenta.png'>Contacto: <a href='mailto:"+contactEmail+"'>"+contactPerson+"</a>");

        }else{

            $("#contactPerson").html("<img class='iconevent' src='img/mi_cuenta.png'>Contacto: <a href='mailto:"+contactEmail+"'>"+contactEmail+"</a>");
        }

        if (contactPhone!=""){
            $("#contactPhone").css("display","block");
            $("#contactPhone").html("<img class='iconevent' src='img/ico-telefono.png'> "+contactPhone+"");
            $("#hrcontactPhone").show();
        }else{
            $("#contactPhone").css("display","none");
            $("#hrcontactPhone").hide();
        }

        if (contactFax!=""){
            $("#contactFax").css("display","block");
            $("#contactFax").html("<img class='iconevent' src='img/ico-fax.png'> "+contactFax+"");
            $("#hrcontactFax").show();
        }else{
            $("#contactFax").css("display","none");
            $("#hrcontactFax").hide();
        }

        if (owner=="false"){
            $("#headeractions").hide();
        }else{
            $("#headeractions").show();
        }

        $("#headeractions").trigger("create");

        member = $(data).find("TheUserIsMember").text();
        url = $(data).find("URL").text();


        $.mobile.changePage("#organization");
        $("#organization").trigger("create");


        $("#divOrga").html("<h3><img src='" + image + "' />" + name + "</h3><p>" + description +"</p>");
        $("#divOrga").attr("data-organizationcode", code);
        $("#divOrga").attr("data-organizationname", name);
        $("#adressOrg").html('<img class="iconevent" src="img/icono_localizacion_25.png"> '+address+" ("+city+")")
        $("#eventsorganization div[data-role='header'] span").html(" Organización "+ ($("#divOrga").attr("data-organizationname")));
        var linkorg = url;
        var patt = new RegExp("(https://|http://)");
        var res = patt.test(linkorg);

        if(res==true){
        $("#urlorg").html("<img class='iconevent' src='img/icono_link.png' />"+ "<a target='_blank' href='"+url+"'>"+url+"</a>");
        }else{
        $("#urlorg").html("<img class='iconevent' src='img/icono_link.png' />"+ "<a target='_blank' href='http://"+url+"'>"+url+"</a>");
        }


        $("#organization").on("pageshow", function() {


            var organizationcode=$("#divOrga").attr("data-organizationcode");
            var eventListOrganization = getEventListOrganization(localStorage.rnl01user, localStorage.rnl01password, "Organizations", "All", organizationcode);
            callWebServiceAsync(URL_API_KERNEL, eventListOrganization, successEventListOrganization);

            function successEventListOrganization(data, textStatus, jqXHR){
                eventsListArray = new Array();
                saveEventList(data);
                if ($(data).find("Error").find("Description").text()){
                    console.log("Array eventsListArray vacio");
                    $("#eventsOrg").empty();
                    $("#eventsOrg").append("<li style='padding:10px;background-color:#ffffff;cursor:auto;' data-role='list-divider'>PRÓXIMOS EVENTOS</li><li style='padding: 10px;font-weight: 100;text-align: left;background-color: white;cursor: auto;'>No hay eventos</li>");
                }else{
                    $("#eventsOrg").empty();
                    $("#eventsOrg").prepend("<li style='padding:10px;background-color:#ffffff;cursor:auto;' data-role='list-divider'>PRÓXIMOS EVENTOS</li>");
                    paintEventListOrganization("#eventsOrg",5);
                }
                $.mobile.loading("hide");

            }

            var organizationOfficialComunication = getOrganizationOfficialCommunicationsRequest(localStorage.rnl01user, localStorage.rnl01password, organizationcode);
            callWebServiceAsync(URL_API_KERNEL,organizationOfficialComunication,successOrganizationOfficialComunicates);
            function successOrganizationOfficialComunicates(data,textStatus,jqXHR){
                comuOfiListArray = new Array();
                saveComuOfiList(data);

                    if ($(data).find("CommunicationList").children().size() == 0) {
                        comuOfiListArray = null;
                        $("#comuOfi").empty(); 
                        $("#comuOfi").append("<li style='padding:10px;background-color:#ffffff;cursor:auto;' data-role='list-divider'>ULTIMOS COMUNICADOS</li><li style='padding: 10px;font-weight: 100;text-align: left;background-color: white;cursor: auto;'>No hay comunicados oficiales</li>");
                    }else{
                        $("#comuOfi").empty();

                        paintComuOfiList("#comuOfi",5);
                        $("#comuOfi").prepend("<li style='padding:10px;background-color:#ffffff;cursor:auto;' data-role='list-divider'>ULTIMOS COMUNICADOS</li>");
                    }
                }


        });



        if (member != "true" && owner != "true") {
            $("#organization div[data-role='content'] a").attr("data-organizationcode", "");
            $("#organization div[data-role='content'] a").hide();

        }else{
            $("#organization div[data-role='content'] a").attr("data-organizationcode", code);
            $("#organization div[data-role='content'] a").show();

        }

        if (member != "true"){
            $("#btnParticipateOrganization").attr("data-organizationcode", code);
            $("#btnParticipateOrganization").show();
        }else{
            $("#btnParticipateOrganization").attr("data-organizationcode", "");
            $("#btnParticipateOrganization").hide();
        }

        if (owner!="true"){
            $("#organization div[data-role='content'] a").attr("data-owner", owner);
            $("a#btnEditOrganization").hide();
            $("a#btnAdminOrganization").hide();
            $("a#btnMembersOrganizations").hide();
            $("a#btneventaddtoorganization").hide();

        }else{
            $("#organization div[data-role='content'] a").attr("data-owner",owner);
            $("a#btnEditOrganization").show();
            $("a#btnAdminOrganization").show();
            $("a#btnMembersOrganizations").show();
            $("a#btneventaddtoorganization").show();
        }

        if (member !="true" && owner !="true"){
            $("#divComuOfi").hide();
            $("#divEventsOrg").hide();
        }else{
            $("#divComuOfi").show();
            $("#divEventsOrg").show();
        }
        if (owner !="true"){
            $("#btnAddComuOfi").hide();
        }else{
            $("#btnAddComuOfi").show();
        }
        if (owner !="true"){
            $("#btneventadd").hide();
        }else{
            $("#btneventadd").show();
        }
        if (url==""){
            $("#urlorg").hide();
            $("#urlorg a").hide();
            $("#hrurlorg").hide();
        }else{
            $("#urlorg").show();
            $("#urlorg a").show();
            $("#hrurlorg").show();
        }



    } else {
        $("#errorPopup .error").html("Ha ocurrido un error al mostrar la organización, por favor ponte en contacto con soporte para arreglar su incidencia");
        $("#errorPopup").popup("open");
    }
    $.mobile.loading("hide");
}
}

当我调用此函数时,页面显示一秒钟然后返回到登录页面,URL不会更改http:// xxxxxxxxx /#organization但该页面与URL不匹配,但它是登录页面。

我尝试删除所有最少代码$ .mobile.changePage(“#organization”); 和$(“#Organization”)。触发器(“创建”);

getOrganization函数,但仍然这样做,如果错误将出现在$(document).bind(“pagebeforechange”,function(event)

中)

知道为什么会这样吗?

感谢所有人。

0 个答案:

没有答案