开发者

Ajax Reload same page onclick

开发者 https://www.devze.com 2022-12-21 06:25 出处:网络
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.

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 l开发者_开发问答oad 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.


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.


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">

Strict DTD doesn't support <noscript>.

0

精彩评论

暂无评论...
验证码 换一张
取 消