tags:

views:

264

answers:

2

Hi,

This is my situation.I have some 10 links on a page. So when user clicks on those links ajax-same page reload must take place.

To be clear I have something like this.

<a href="test.php?name=one">one</a> | <a href="test.php?name=Two">Two</a>

If javascript is enabled,

Onclick, ajax load must take place.

If javascript is disabled, Then the above should work.

Basically I am using "name" to limit some values of my search page.

A: 

Here's what you do....

There's a <noscript> tag that is available for those who do not have Javascript enabled on the browser.

If the page renders the <noscript> tag, the <a> click should run as normal, else the ajax call.

Usually what people do is to write the same page twice, one containing no javascript and the other with.

e.g

<script type="text/javascript">
   //Functions goes here...
</script>
<noscript>
  <!-- redirection -->
</noscript>

More on <noscript> here: http://xhtml.com/en/xhtml/reference/noscript/

UPDATE: Use the following DTD on your page.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

Strict DTD doesn't support <noscript>.

The Elite Gentleman
Thank you.. I will look into it. But below code is some what working.
PS. Check my post to see what DTD you need to use. Sorry to have not included it earlier.
The Elite Gentleman
Thanks a lot.. I guess this can help me easily. I am thinking of doing something like ajax load onclick and reload if js disabled. Since jquery will not be called if js is disabled "noscript" may not be required right?
Do like GMail does it. When Javascript is disabled, they redirect to another Synchronous page (i.e. only hyperlinks are used) instead of using Ajax. They follow the principle I gave as solution. Try and debug it (use Firebug for Firefox to see code). :-)
The Elite Gentleman
A: 

Attach click handlers to your links unobtrusively:

$(function() {
    $('a').click(function() {
        // resultContainer is the id of some element that will receive
        // the HTML from the link
        $('#resultContainer').load(this.href);
        return false;
    });
});

If javascript is disabled links will perform standard requests reloading the whole page.

Darin Dimitrov
This is somewhat working.. But it is printing links twice. How to avoid that.. Thanks a lot...