On Dec 8, 2005, at 12:12 AM, Rune Hansen wrote:
On 7. des. 2005, at 23.52, Bob Ippolito wrote:
Generating a random number is insignificant. A timestamp would
probably be better though given the use case.
Anyway, the right answer is to do it from JavaScript if you have
to do it at all. Doing it from the TG side is nearly worthless
because only one unique identifier is going to end up in the page,
but you almost definitely need to fetch that JSON URL more than
once during the page view.
Is it *really* that hard?
loadJSONDoc(url, {uid: (new Date()).getTime()});
or if you already have a query string in there you'd have to do it
yourself:
loadJSONDoc(url + "&uid=" + (new Date()).getTime());
I may not have made my self completely clear in my original proposal.
I'm unable to make loadJSONDoc("${std.url('/
Edit'/,rand="+Math.random()+"tg_format='json')}") work. KID
obviously frowns upon gluing together a template function.
The one way I found to get this to work was to have
turbogears.stdvars create the hash when firing the ${std.}
function: loadJSONDoc("${std.url('/Edit'/,rand=std.hash
(),tg_format='json')}")
So don't do it like that. Don't generate JavaScript code, that's
bad. Embed the URL in the document somewhere, and scrape it out from
the DOM. Good way to do this is with a hidden input tag.
That way the hash gets created only when using the ${std.} function
in a template, and it guarantees a "fresh" hash every time function
${std.} is called.
Which happens when the HTML is rendered. Like I said, you can't call
the JavaScript twice in a given page load and have a different number
come out because it was generated by the server.
If you're only going to load the JSON exactly once, why not just put
the data in the document to begin with?
-bob