如何使AJAX称为页面重新加载在浏览器

编程入门 行业动态 更新时间:2024-10-27 00:34:02
本文介绍了如何使AJAX称为页面重新加载在浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

首先我想说的是,我尝试过很多codeS和插件,但没有为我工作。我只是试图让按钮后退和前进在浏览器中再次调用AJAX称为页,使他们出现在按钮点击后。我希望你能,我不是开发商:)

请帮我的家伙,这些都是工作日内在这个非常时刻...:)

的处理程序:

<李>< A HREF =#级=CENI>примерницени< / A>< /李> <李>< A HREF =#级=karieri>кариери< / A>< /李>

JavaScript的:

$('。CENI)。点击(函数(){     $阿贾克斯({         网址:'页/ ceni.php',         成功:函数(响应){             $(#页)HTML(响应);         }     }); }); $('。karieri)。点击(函数(){     $阿贾克斯({         网址:'页/ karieri.php',         成功:函数(响应){             $(#页)HTML(响应);         }     }); });

解决方案

最常用的方法是使用一个插件监测hashchange事件,并再次请求AJAX页面。

<李><一类=CENI的href =#CENI>примерницени< / A>< /李> <李><一类=karieri的href =#karieri>кариери< / A>< /李>

设置散列变化处理程序:

的jQuery(窗口).bind('hashchange',函数(){   变种pageHash = location.hash.substr(1);   如果('CENI | karieri |'.indexOf(pageHash +'|')> = 0){     。jQuery的(#页)负载(pageHash +.PHP);   } });

加载内容转换成通过jQuery一个元素被记录在 api.jquery/load/

作为一种替代方法,您可以使用HTML5历史API文档的 html5demos/history - 它可以让你保持在地址栏看整齐,不得散列

如果您需要支持IE7及以下,使用polyfill的hashchange事件,如 HTTP ://benalman/projects/jquery-hashchange-plugin/

First thing i want to say is that i tried many codes and plugins, but nothing work for me. I am trying only to make the buttons "back" and "forward" in the browser to call again the AJAX called pages so they appear after the buttons are clicked. I hope you get that i am NOT developer :).

Please help me guys, these are days of work in this very moment...:)

The handlers:

<li><a href="#" class="ceni">примерни цени</a></li> <li><a href="#" class="karieri">кариери</a></li>

The javascript:

$('.ceni').click(function(){ $.ajax({ url: 'pages/ceni.php', success: function(response) { $("#pages").html(response); } }); }); $('.karieri').click(function(){ $.ajax({ url: 'pages/karieri.php', success: function(response) { $("#pages").html(response); } }); });

解决方案

The most common method is by using a plugin for monitoring the hashchange event and re-requesting the ajax page.

<li><a class="ceni" href="#ceni">примерни цени</a></li> <li><a class="karieri" href="#karieri">кариери</a></li>

Set up the hash change handlers:

jQuery(window).bind('hashchange', function() { var pageHash = location.hash.substr(1); if('ceni|karieri|'.indexOf(pageHash + '|') >= 0) { jQuery("#pages").load(pageHash + '.php'); } });

Loading content into an element via jQuery is documented at api.jquery/load/ and is fundamentally the same as using jQuery.ajax to make the request.

As an alternative, you can use the HTML5 history API documented at html5demos/history - which allows you to keep the address bar looking tidy without the hashes.

If you need to support IE7 and below, use a polyfill for the hashchange event such as benalman/projects/jquery-hashchange-plugin/

更多推荐

如何使AJAX称为页面重新加载在浏览器

本文发布于:2023-11-24 22:36:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627155.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   浏览器   页面   AJAX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!