Member Avatar for kingben

Hi.
I am serving the contents of the page based on the navigation anchor links.
e.g.
http://somesite.com/index.html#home will serve the home page contents.
http://somesite.com/index.html#about will serve the about page contents.

The contents are stored in contents.php page and are written in the below tag inside index.html

<div id=contents>
<!-- Contents Here -->
</div>

While I am navigating away from #home to #about, I want the contents division to show a loading image.
Can you please help me over that?

Kingben,

If you wish to navigate with urls of the form http://somesite.com/index.html#xxx then the #xxx bit (url.hash) will navigate to a named anchor (of the form <a name="home"></a>) on the same page.

If all pages are really one page (index.html) divided into sections, then you do not need a "loading" message while navigating between them. On most computers, most pages will scroll just about instantaneously to the required section of the page. High speed is pretty well guaranteed due to the fact that the page does not need to be se-served. It's already on screen and browsers are smart enough to know not to re-request it (unless in exceptional circumstances, I think, the page was served with a no-cache header or meta).

Much the same applies if you want to use a script to switch one section off and another on - the effect will be just about instantaneous (for most pages on most computers most of the time) so again no "loading" message is necesary. If it appeared at all then the message would typically be on screen for such a short time, few people would ever read it.

If however, you need to fetch the content from the server, either by conventional (hyperlink) means or with AJAX methods, that's different; delay can warrant the display of a loading message.

That said, for most part it is accepted by web programers and users alike that conventional hyperlinks do not generally warrant a "loading" message. Modern browsers give several strong cues to indicate that a request is being processed.

Airshow

Member Avatar for kingben

Kingben,

If you wish to navigate with urls of the form http://somesite.com/index.html#xxx then the #xxx bit (url.hash) will navigate to a named anchor (of the form <a name="home"></a>) on the same page.

If all pages are really one page (index.html) divided into sections, then you do not need a "loading" message while navigating between them. On most computers, most pages will scroll just about instantaneously to the required section of the page. High speed is pretty well guaranteed due to the fact that the page does not need to be se-served. It's already on screen and browsers are smart enough to know not to re-request it (unless in exceptional circumstances, I think, the page was served with a no-cache header or meta).

Much the same applies if you want to use a script to switch one section off and another on - the effect will be just about instantaneous (for most pages on most computers most of the time) so again no "loading" message is necesary. If it appeared at all then the message would typically be on screen for such a short time, few people would ever read it.

If however, you need to fetch the content from the server, either by conventional (hyperlink) means or with AJAX methods, that's different; delay can warrant the display of a loading message.

That said, for most part it is accepted by web programers and users alike that conventional hyperlinks do not generally warrant a "loading" message. Modern browsers give several strong cues to indicate that a request is being processed.

Airshow

Hey thanks for the reply. Think of this ....... on clicking #xxx i process a MySQL statement that may take 2-3 mins. to complete (based on the DB size) .... Since clicking on #xxx only updates the <div> tags that i have set, the browser is not showing any loading... status .......

In this case it becomes mandatory for me to show it ....

Hey thanks for the reply. Think of this ....... on clicking #xxx i process a MySQL statement that may take 2-3 mins. to complete (based on the DB size) .... Since clicking on #xxx only updates the <div> tags that i have set, the browser is not showing any loading... status .......

In this case it becomes mandatory for me to show it ....

Yup, with a 2-3 minute delay, a message is pretty well mandatory.

But then I can't work out why you would want to use a url ending in #xxx - which implies the content is already sitting there on the page. Of course, there's nothing to stop you using such a url, but the hash element appears to be redundant, unless I'm missing something.

Airshow

Member Avatar for kingben

Yup, with a 2-3 minute delay, a message is pretty well mandatory.

But then I can't work out why you would want to use a url ending in #xxx - which implies the content is already sitting there on the page. Of course, there's nothing to stop you using such a url, but the hash element appears to be redundant, unless I'm missing something.

Airshow

well yes, you are missing a bit. THE CONTENTS ARE NOT THERE!
I am using jQuery to fetch my contents based on Anchor Links

$.get("contents.php",query, function(data){
			$("#middlePanel").html(data);
		});

Though contents.php consists of all the contents that my page will serve to the user, they are not loaded at once onto the page. I am not using anchor links as "named" html links.
I am using them as a means to fetch the required contents from contents.php

switch($_GET['section']){ //here section is the xxx of #xxx
	case 'home':
        echo "you are viewing home contents";
        case 'about':
        echo "about me";
         default:
         echo "invalid Anchor Passed";
}

Aha, OK I understand but I still have a problem.

Whereas there's nothing to stop you composing your URL with url.hash to be used for server-side branching), you are into some diy server-side url parsing to extract the hash substring. As far as I'm aware, php does not parse it out for you like $_GET, $_POST, $_COOKIE and it doesn't appear in $_SERVER.

In addition, it would be confusing for anybody who ever has to maintain your code (maybe even yourself in a year's time) to use hash in this unusual way.

It would be more conventional to compose the urls more like this

Where p stands for page.

Thus, the content being requested is determined by the value of $_GET and you can branch on this in your php switch statement.

If the server needs a particular value that also needs to appear in the hash part of a request, then include it twice. Here is an example from phpBB forum url:

http://www.myForum.com/phpbb2/viewtopic.php?p=39824#39824

In general, pleeeeeease avoid hash in the request unless it is to be interpreted by the browser to scroll to a named anchor.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.