1

Currently, when a user goes to the following URL:

www.foo.com/details.hmtl#id=123

The server returns 'details.html' and then performs a client-side Ajax call once the page is returned to load the data for the item with id=123. It uses the BBQ Plugin for JQuery

Is there any way to retrieve the parameters following the hashmark on the server so that when the page is initially being returned by the server, it can be returned containing the details for id=123.

This is desired so that details will still be displayed whether or not Javascript is turned on in the user's browser. And if they have Javascript turned on, they can change out the content via Ajax by clicking the existing buttons on the site.

Thanks in advance for all help

EDIT:

The pages are currently being returned in the following manner:

id = self.request.get("id")
template_values= {'id': id}
path = os.path.join(os.path.dirname(__file__), 'details.html')
self.response.out.write(template.render(path, template_values))
James Allardice
  • 164,175
  • 21
  • 332
  • 312
Cuga
  • 17,668
  • 31
  • 111
  • 166

3 Answers3

3

You cannot do that because the browser sends just the /details.html for request.

if you need to you can use parameters for example : for the first time you can send the user to this page /details.hmtl?id=123 then save the user's request in the session value and redirect the user to the real page without params and with hash /details.hmtl#id=123 then get the current user's session and render the page's content.

That's how you can do it without using JS

Regards NiL

NiL
  • 287
  • 4
  • 10
  • Thanks, this sounds like what I'd like to do. Could you possibly show an example how I might save the user's request in the session and redirect to the page without params? I've edited the answer to include the server-side code for how I return the details.html. – Cuga Jan 04 '11 at 14:38
  • Nevermind, I figured out how to do the redirect: self.redirect("/details.html?id=" + id). Thanks for your help! – Cuga Jan 05 '11 at 15:05
0

The part after the anchor (#) is never sent to the server by the browser unless you hack your way around it. Here's a way you can do it using cookies: http://www.stoimen.com/blog/2009/04/15/read-the-anchor-part-of-the-url-with-php/

albertov
  • 2,314
  • 20
  • 15
  • Thanks. Unfortunately, I don't think this would be of use to me as my main goal is to get this working without using any JS (or cookies). – Cuga Jan 04 '11 at 14:10
-1

Why are you using # for this? The first part of NiL's answer is to use an actual query ? instead, and I'd second that. But don't bother redirecting to generic pages etc. You want a page with the information about id 123 on it, so return that from the server! You're actively choosing to turn a single request for a page about id 123 into a request-generic response-specific request-specific response cycle, for no apparent reason, and that's for the normal case where the user does have javascript!

By all means use dynamic stuff and change the page for the second request, but by then you already know the user has javascript. For the first request, stick with ?id=123 and give them to complete page.

Why complicate it and slow it down?

Phil H
  • 19,928
  • 7
  • 68
  • 105
  • Because currently, this is how it's written. I plan on rewriting it to behave in the manner you describe, but I have to figure out how first. Problem is the current pages require JS to load anything, so the question was asked to see the feasibility of tweaking the existing server function (by grabbing the id following the #) rather than redoing the entire page. – Cuga Jan 04 '11 at 16:05