Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

[FEATURE] Parameters for pages #471

Closed
tiegz opened this issue Nov 15, 2010 · 9 comments
Closed

[FEATURE] Parameters for pages #471

tiegz opened this issue Nov 15, 2010 · 9 comments

Comments

@tiegz
Copy link

tiegz commented Nov 15, 2010

I haven't spelunked through the whole codebase yet, but this is a feature that would be really helpful.

Scenario:

  • I have one file (index.html) with multiple pages (ie "parent", "child")
  • I want to load the "child" page from a list in the "parent" page (but with data loaded via some JSON resource for the "child")
  • This would require an "id" parameter, so the link url would be something like "#child?id=123"
  • When the "child" page is loaded, then we'd somehow have the "id=123" param available to load via AJAX and populate the page.

Currently we can't do this b/c we can't have a "child?id=123" page for every single ID on "index.html". If we could do that, we could also link to the full url directly ("index.html#child?id=123") to get that "child" resource.

If there's not already a way to do this, I'd be willing to help out on this feature if anyone is 'int.

@TZAdvantage
Copy link

Very useful. One more vote for this feature.

I would like to have this "querystring" as an associative array in the pageshow event.
You would then be able to access it like param["id"].

@celogeek
Copy link

I'm totally for this feature.
I haven't got any clue how to use the data in changePage and to get this data in the view (without server side).
I have try to get in data-role="page", at the end, the location.href, but it seems url is update after the process.
And we have to parse the querystring manually.

A simple way to get params on new page in javascript, should be wonderfull !

@toddparker
Copy link
Contributor

Closing and moving to the feature requests page for post-1.0:
https://github.com/jquery/jquery-mobile/wiki/Feature-Requests

@IgitBuh
Copy link

IgitBuh commented Jun 14, 2011

Is there any chance this could be reconsidered for being included already for 1.0?
Most of the features being on the to-do list for post 1.0 can be considered as a nice "plus" afaic, but this one seems to be essential to me. I don't know any useful website without GET parameters. They're essential for passing links and setting bookmarks. Same goes for JQM-Web-Apps.
When presenting dynamical content to the user there's simply no way to work without passing IDs. I tried a lot of workarounds for this. Setting the ID in a global variable only allows to load the content page in the same session (refreshing the page, setting a bookmark, etc. don't work). The only way to enable the user to reload the content page is to write the ID for the required content to a cookie, which actually works, but seems ridiculous to me (besides the fact that it still doesn't allow setting a bookmark or sending the link to somebody).

Something like "#page?id=1" or "index.html?id=1#page" (which looks a bit strange, but represents the URL standard) would be very, very appreciated.

To be honest, I don't consider this to be a huge change in the current navigation structure (since it's optional) neither do I consider the implementation effort for this to be too high. There are plenty of threads in the forum showing that people need this, or better said they expect it to be possible as using GET parameters is part of web coding.
I think it should be present when 1.0 goes public at the latest, actually already for beta1, as it's supposed to be feature-complete at that point.

Thanks.

@toddparker
Copy link
Contributor

IJay - Can you provide more details on what you're looking for so we can give it some thought?

@IgitBuh
Copy link

IgitBuh commented Jun 14, 2011

Sure. To make it simple I'd like to break it down to one certain use case:
I'm implementing a web app that allows monitoring certain hardware devices. The list of those devices is created dynamically depending on the user that is logged in (that works perfectly so far). Clicking on one of those devices changes the page (index.html#Overview) to another page (index.html#Details) that shows the details. The details page is basically the same for all devices but of course is supposed to show device specific information. All the information is gathered dynamically via Ajax/JSONP.

Now when calling the details page a device id needs to be passed so the according device information can be retrieved.
Right now a href value can only be like this:
index.html#Details
However, this doesn't contain any information about what details to show.
It's necessary to pass a parameter in the URL that can be used by the page that has been called, like:
index.html#Details?id=123 or index.html?id=123#Details
So that the value of id can be used on the page (in PHP it's used as a $_GET[...] variable, but for JS there are some easy functions to use GET parameters as well). That way calling http://.../index.html#Details?id=123 would always show the details for device 123. I can bookmark that, I can send the link to somebody else, I can simply hit the refresh button in the browser.
The problem is, that JQM can't handle any parameters in its URL structure right now. So what we need is a way to pass parameters in JQM like the two examples that I made.

Thank you very much for listening and taking suggestions seriously!

@IgitBuh
Copy link

IgitBuh commented Jun 15, 2011

Just to make it clear: It's not about only one parameter but about making it flexible to use parameters in general. So something like this should be possible as well:
index.html?id=123&type=new&name=foo#Details
A small piece of JS code how to read those GET parameters would be e.g.:
http://www.netlobo.com/url_query_string_javascript.html

I guess the easiest way to implement this would be to simply ignore everything between a '?' and a '#' in the URL (or if there's no '#', simply everything after a '?').
A more elegant way (maybe even in a later step) would be to parse those parameters directly in JQM to offer a native way to access them s.th. like $.mobile.get['id']

@azicchetti
Copy link

I've written a simple controller/router for jquery mobile that also provides support for parameters in the url, among other things (through an ugly hack of binding a custom live event to anchors...).

The project goal is providing a jqm-event-aware controller, but it can be used just to enable parameters for pages.
I've tested it with the latest jqm version at "http://jquerymobile.com/test/js/", with previous versions it doesn't work (but I guess that with a little debugging I could fix it).

https://github.com/azicchetti/jquerymobile-router

@scottjehl
Copy link

Hi all, I've posted a comment on the #2082 that will hopefully help you out with this. #2082 (comment)

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants