ajax & location

S

sandro

Hi,

I just landed in the wanderful world of ajax w/ jquery. Applying ajax
call to menu items was a really easy experience but I'm stuck with a
problem.

If I load the content of a page via ajax call, I'd also like to change
the location attribute of the page so that a further window.reload()
would reload the correct one. Is that possible and how? If I assign
window.location if seems it triggers an immediate reload of the page
that I would like to avoid.

Thanks for any possible hints

sandro
*:)
 
R

rf

sandro said:
Hi,

I just landed in the wanderful world of ajax w/ jquery. Applying ajax
call to menu items was a really easy experience but I'm stuck with a
problem.

If I load the content of a page via ajax call,

Why on earth would you load the contents of an entire page using ajax? What
is wrong with a simple link?

The source where you discovered this [sic]wanderful world should be called
into question if it's teaching you things like this.
I'd also like to change
the location attribute of the page so that a further window.reload()

Why do you do a further window.reload()?
would reload the correct one. Is that possible and how? If I assign
window.location if seems it triggers an immediate reload of the page

As it should. That's what it is designed to do.
that I would like to avoid.

But wht? You *are* reloading the whole page. Up there where you said "if I
load the content of a page via ajax".
Thanks for any possible hints

Use a standard links. Use ajax for what it is designed for, re-loading
little tiny bits of a page.

What you are doing is a bit like using frames, and we all know how bad that
is.
 
S

sandro

rf said:
Why on earth would you load the contents of an entire page using ajax? What
is wrong with a simple link?

I don't load a *whole* page. I fill a #content div that doen't have to
have header, footer, css, javascript navigation bar and so on. As I use
dynamic ineriting templates I can detect if the tempate should be
rendered as simple content or a complete page, that makes it possible to
be used with or without javascript without changing html code.

That turns out to be faster while rendering the page on both server and
client side

Why do you do a further window.reload()?

Some of the links in the page may open popup to add/delete entries, when
the popup closes i normally trigger a window.reload() to refresh page
content. At the moment that redirects me to the first page that was
opened and I clearly need to avoid it.

Moreover, I like if the user can bookmark a page that is seeng and
that's not possible if I changed the content with ajax, unles it's
possible to change the url as well

Does it make more sense now?

sandro
*:)
 
D

Diesel

Stefan said:
You could try assigning to window.location.hash. Your script would then
need to read that part of the URL onload (or DOMReady) and decide which
content to load. There's a number of examples for this on the web, they
should be easy enough to find.

This pattern has a number of drawbacks, including history navigation
oddities, browser support, visitors without JS, and search engine
optimization. If there's no specific reason why you don't just want to
load a new page, it's probably best avoided. A SJ slideshow would be a
better application for it.

Thanks for the hints. I'll better investigate them. I'd like to further
refine the question that is both practical and "theorical" in the sense
how can be obtained, not as code but as method.

If you have a look at
http://flowplayer.org/tools/demos/tabs/ajax-history.html you see an ajax
tab with history support. When you click on a tab the URL in the browser
changes and a further reload() will stick to that page. My question is:
how can conceptually be implemented such a thing?

sandro
*:)
 
G

Gregor Kofler

Diesel meinte:
If you have a look at
http://flowplayer.org/tools/demos/tabs/ajax-history.html you see an ajax
tab with history support. When you click on a tab the URL in the browser
changes and a further reload() will stick to that page. My question is:
how can conceptually be implemented such a thing?

Simple. The script only changes the fragment, which will never reload
the page. The content of all tabs resides on the same page.

Gregor
 
T

Thomas 'PointedEars' Lahn

sandro said:
I just landed in the wanderful world of ajax w/ jquery.

That's in fact _crash-landed_. Avoid jQuery if you can (see previous
discusssions).
If I load the content of a page via ajax call, I'd also like to change
the location attribute of the page so that a further window.reload()
would reload the correct one. Is that possible and how?

You could assign to the `window.location.hash' property, or:
If I assign window.location if seems it triggers an immediate reload of
the page that I would like to avoid.

That depend on what you assign, of course. If you assign a string that
contains only a URI-reference with a fragment part, no reload should take
place.

window.location = "#foo";

Subsequent "ajax calls" (_XHR listeners_, really) can then read the
`document.URL', `window.location', `window.location.href', or
`window.location.hash' properties to determine the target state of the
application. Until events are being introduced for the target environment,
you need to poll the value of one of these properties regularly to
recognize the change.


PointedEars
 
S

sandro

Thomas said:
That's in fact _crash-landed_. Avoid jQuery if you can (see previous
discusssions).

sorry I wasn't able to understand to which thread you where pointing,
would you tell me the subject or give the link?
thanks

*:)
 
S

sandro

Gregor said:
Diesel meinte:


Simple. The script only changes the fragment, which will never reload
the page. The content of all tabs resides on the same page.

Ok, very simple, now I understand why a slideshow is a better
implementation that what I was doing with menus

A far as the reload() problem I could use a function instead of the
reload() and look for a variable that I could have left in the location
object as an additional attribute (eg.: location.next_reload). Would
that be considered bad code? I do realize that would be a partial
solution, no way to bookmark the page...

*:)
 
R

rf

sandro said:
Gregor Kofler wrote:
A far as the reload() problem I could use a function instead of the
reload() and look for a variable that I could have left in the location
object as an additional attribute (eg.: location.next_reload). Would
that be considered bad code? I do realize that would be a partial
solution, no way to bookmark the page...

Worse than that. If the page cannot be bookmarked it cannot, and will not,
be indexed by the search engines.
 
C

Cody Haines

sandro said:
Ok, very simple, now I understand why a slideshow is a better
implementation that what I was doing with menus

A far as the reload() problem I could use a function instead of the
reload() and look for a variable that I could have left in the
location
object as an additional attribute (eg.: location.next_reload). Would
that be considered bad code? I do realize that would be a partial
solution, no way to bookmark the page...

*:)
Did you decide against the location.hash solution? That's by far the
best available solution to what you're asking
 
D

Diesel

Cody said:
Did you decide against the location.hash solution? That's by far the
best available solution to what you're asking


No, but as far as I understand, that's a good solution for tab-like
pages, where the contents are already there or for menu that share the
location.pathname. In the case that pushed me here I have different
pathnames for diffenren menu entries.

Event in the example [1] the externally loaded page is added in the
hash, but the loa
http://flowplayer.org/tools/demos/tabs/ajax-history.htmding of that page
is handled by that tab wiget, not simply by the window.reload(), correct?

sandro
*:)
 
R

Richard Cornford

Diesel meinte:


Simple. The script only changes the fragment, which will never
reload the page.
<snip>

That is a bit of an exaggeration. Opera 6, for example, did reload the
page upon assignments to - location.hash -, so the outcome will be
browser dependent. Probably what can be said is that this has become
such a common way of clawing back the history/bookmarking support,
that the browser would have provided if it had not been coded out of
the system, that these days any browser released that does reload the
page upon assignment to - location.hash - is going to look too broken
for realistic use.

Richard.
 
T

Thomas 'PointedEars' Lahn

sandro said:
sorry I wasn't able to understand to which thread you where pointing,
would you tell me the subject
jQuery

or give the link?

The _links_ (at least 50). Google is your friend. [psf 6.1]

You're welcome.


PointedEars
 
R

Richard Cornford

On 2/15/10 6:19 AM, Richard Cornford wrote:
Actually, Opera has been doing this (reload the page) at least
up until (and including) version 8.54.
<snip>

Any single example is unlikely to be intended as an exhaustive list.
Opera 6 is the one where I was certain of the behaviour, and so an
accurate example.

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
VetaMcRae
Top