John Zumbrum
John Zumbrum

Reputation: 2856

Jquery Mobile Change Page w/ Parameters

I have two pages: SRDashboard.html and SREventInfo.html

The dashboard contains a list of events, and the other page is for viewing one of those events. I have it setup so that after clicking on one of the events in the list, a loadEvent method is called, and that executes the following code:

$.mobile.changePage(Config.PageNames.EventInfo, { dataUrl : Config.PageNames.EventInfo + "?eventId=" + eventId, data : { eventId: eventId }, reloadPage : true, changeHash : true });

As you can see it's passing the eventId. I can see that it's doing this through firebug, and that the parameter is there like I need it.

In SREventInfo.html I have the following block:

<div data-role="page" id="EventInfoPage">
            <script type="text/javascript">
                $("#EventInfoPage").live('pageinit', function () {
                        var url = $.url(document.location);
                        alert(document.location);
                        var eventId = url.param("eventId");
                        alert(eventId);
                });
    </script>
</div>

What happens here is that my first alert comes up with the url being SRDashboard.html, and eventId being undefined. What am I doing wrong?

Upvotes: 0

Views: 1333

Answers (1)

Gajotres
Gajotres

Reputation: 57309

I am using this method, this is a jQM way, at lease for the versions 1.0 and 1.1:

$("#EventInfoPage").live('pagebeforeshow', function () {
    var eventId = $(this).data("url").split("?")[1];;
    eventId = eventId.replace("eventId=","");   
    alert(eventId);
});

Upvotes: 2

Related Questions