473,385 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

ajax bookmark problem

I"d like to hear critiques on the following method for dealing with the
back button and bookmarkability problem with AJAX. Whenever I do
something on a page with ajax, I add to document.location.hash (which
doesn't reload the page but does include the parameters in a bookmark)
like so:

document.location.hash = document.location.hash + '&param=value';

So the URL gets updated like so:
http://host.com/cgi-bin/foo.cgi?cmd=bla#&param=value;
When that page is loaded from that bookmark, I'm converting that
information in the hash to the query (which reloads the page with those
parameters in the URL and drops the hash):

var hash = document.location.hash.substr(2);
if (hash.length > 0){
var searchadd = '';
var elements = hash.split('&');
for (i=0;i<elements.length;i++){
searchadd = searchadd + '&' + elements[i];
}
document.location.href=document.location.pathname +
document.location.search + searchadd;
}

Is it correct that the hash (i.e. everything after the # in the URL) is
only available client side?

The reload to incorporate those parameters in the URL is time consuming.
It takes an additional 60-90 seconds over a URL that doesn't need to be
corrected. Is there a better way?
Jan 30 '06 #1
2 2087
Hi Tony,
Try this tutorial [
http://dev2dev.bea.com/pub/a/2006/01...ck-button.html ]. Hope it
helps.

with regards,
Peroli Sivaprakasam

Jan 31 '06 #2
Tony Rice wrote:
I"d like to hear critiques on the following method for dealing with the
back button and bookmarkability problem with AJAX. Whenever I do
something on a page with ajax, I add to document.location.hash (which
doesn't reload the page but does include the parameters in a bookmark)
like so:

document.location.hash = document.location.hash + '&param=value';

So the URL gets updated like so:
http://host.com/cgi-bin/foo.cgi?cmd=bla#&param=value;
Not really.

Zeroth, `document.location' is deprecated long since. Use `window.location'
instead.

First, you add to location.hash. However, location.hash may or may not
contain the leading `#' character, depending on the UA's DOM.

Second, there are user agents which do not honor RFC3986 in this regard,
meaning that a "&foo" is considered a part of the URI's `query' component
even if it is after the `#'. You should therefore omit the `&'.

Third, you have to escape (percent-encode) the content of the query-part or
the hash component.
When that page is loaded from that bookmark, I'm converting that
information in the hash to the query (which reloads the page with those
parameters in the URL and drops the hash):

var hash = document.location.hash.substr(2);
if (hash.length > 0){
var searchadd = '';
var elements = hash.split('&');
for (i=0;i<elements.length;i++){
`i' is undeclared, therefore either it is global or the assignment can
result in an error. Comparing against the unchanged elements.length in
every loop is inefficient.

for (var i = 0, len = elements.length; i < len; i++)
{
searchadd = searchadd + '&' + elements[i];
}
document.location.href=document.location.pathname +
document.location.search + searchadd;
However, this does not make much sense. First you split the fragment part,
then you concatenate it again.

You should choose another delimiter for the fragment part components, then
use `&' to join them and concatenate with location.search. Example:

window.location = window.location.pathname + window.location.search +
"&" + hash.split("_").join("&");
}

Is it correct that the hash (i.e. everything after the # in the URL) is
only available client side?
It appears so. Even with PathInfo, I have not been able to create a
request that includes the fragment component. However, I remember to
have read something about URL rewriting which used the `#' in a request;
unfortunately, I do not remember where.
The reload to incorporate those parameters in the URL is time consuming.
It takes an additional 60-90 seconds over a URL that doesn't need to be
corrected. Is there a better way?


Efficient programming.
HTH

PointedEars
Jan 31 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: DrFoo | last post by:
(Access 97 and 2003) Hi, Here's a smippit of code that works correctly about 95% of the time. This part of the algorithm... - find the first value = true - if found, find next value =...
2
by: corepaul | last post by:
I am fairly new to Access and I have a problem trying to use bookmarks with a recordset. I have a recordset dimensioned as, Dim rstFoodDesc As ADODB.Recordset ' recordset Dim bMark As...
5
by: Kaur | last post by:
Hi, I am having a strange bookmark problem. I have a main form called frmSurveyQSubQ. This form has a subform called sfrmRespodent. SfrmRespondent has a sfrm in it called sfrsfrmResponses. I have...
3
by: equazcion | last post by:
Hi, I have an image reference (IMG) in my page that changes depending on the value of a database field. Clicking the image triggers an Ajax call to change the database field (toggles the field...
3
by: dhsieh | last post by:
I am trying out nested AJAX calls for the first time, but I seem to have hit a snag. The code snippet is the outer AJAX call and a function, it gathers information about a company. As we get towards...
2
by: willl69 | last post by:
Hi All, Ive been having a problem of late with one of my sites that uses PHP5 / Ajax. The problem is that periodically the ajax functions lock up and it gets stuck in the loading phase of the...
3
by: willl69 | last post by:
Hi All, Ive been having a problem of late with one of my sites that uses PHP5 / Ajax. The problem is that periodically the ajax functions lock up and it gets stuck in the loading phase of the...
6
by: John Doe | last post by:
Here's my issue: I have an instant messenger type feature for my site, its basically an ajax IM feature. I run with a mysql backend on the site, i have a div on my main page that runs a javascript...
8
by: cyqotiq | last post by:
First, let me state that this is not necessarily a Firefox problem, as I haven't fully tested in IE just yet. Second, let me state that this is not the typical "getElementById not working Firefox"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.