热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何在github源代码浏览中实现AJAX?-HowAJAXisdoneingithubsourcebrowse?

Githubhasareallynicesourcebrowser.Navigatingbetweendifferentpathsintherepogeneratesaj

Github has a really nice source browser. Navigating between different paths in the repo generates ajax calls to load the content (as you can clearly see in the firebug log). The ajax call returns the html of the new list of files to be displayed. In addition to changing the view list of files, the url changes as well. However it does not use fragments like most ajax deep-linked sites (use of #). At github the whole url changes.

Github有一个很棒的源浏览器。在repo中的不同路径之间导航会生成ajax调用来加载内容(您可以在firebug日志中清楚地看到)。ajax调用返回要显示的新文件列表的html。除了更改文件的视图列表之外,url也会更改。但是它不像大多数ajax深层链接站点那样使用片段(使用#)。在github上,整个url都变了。

For example at django repo at https://github.com/django/django going to django folder will generate ajax request to https://github.com/django/django/tree/master/django?slide=1&_=1327709883334 which will return the html content of the folder. The link will also change to https://github.com/django/django/tree/master/django. As you can see this new link does not use a fragment.

例如,在django repo上(https://github.com/django/django去django文件夹),将生成对https://github.com/django/django/tree/master/django?幻灯片=1&_=1327709883334将返回文件夹的html内容。该链接还将更改为https://github.com/django/django/tree/master/django。正如您所看到的,这个新链接不使用片段。

How is that done? I always thought that ajax based sites have to use url fragments (#) to achieve deep linking but apparently it is not so.

是怎么做到的呢?我一直认为基于ajax的站点必须使用url片段(#)来实现深度链接,但显然不是这样。

2 个解决方案

#1


4  

Well, as was described in the comments by Dav, it appears that GitHub does not use the pAjax library. Due to the fact that I ended up answering with an "incorrect" information (actually I think I had seen something related to GitHub using pAjax when I was answering this question, but at the moment I can not find the source), I went after the correct answer.

正如Dav注释中描述的那样,GitHub似乎并不使用pAjax库。由于我最终回答了一个“不正确”的信息(实际上我认为我在回答这个问题的时候看到了一些与GitHub有关的东西,但是当时我找不到来源),我就去寻找正确的答案。

I did not find anything official on the part of developers regarding whether any library was used, only found a post saying that the History API was used: https://github.com/blog/760-the-tree-slider

关于是否使用了任何库,我没有找到任何开发人员的官方信息,只是找到了一个帖子,说使用了History API: https://github.com/blog/760thetree -slider

Then came to my head, why not ask the code itself?

然后来到我的脑海,为什么不问问代码本身呢?

Using Chrome (in reality any browser with a decent developer tools), open a repository (in this case, pAjax), right-clicking on any directory, simply choose inspect element.

使用Chrome(实际上是任何拥有优秀开发工具的浏览器),打开一个存储库(在本例中是pAjax),右键单击任何目录,只需选择inspect元素。

Inpect Element

This will display the a element responsible for the directory link.

这将显示负责目录链接的a元素。

HTML Structure

A "suspect" class showed up, let's search for it on the Javascript source of the page.

出现了一个“可疑”类,让我们在页面的Javascript源上搜索它。

The Codez!

And here it's, the click event handler for the directory link, in addition to the entire code related to the animation and the History Api. And as can be noted, it's not used any library behind the History Api. Don't forget to mark the Pretty Print option.

这里是目录链接的单击事件处理程序,以及与动画和历史Api相关的整个代码。可以指出,它没有使用历史Api背后的任何库。不要忘记标记漂亮的打印选项。


Old and incorrect answer

GitHub uses the jQuery plugin pJax (pushState + Ajax), which uses the HTML5 history API.

GitHub使用jQuery插件pJax (pushState + Ajax),该插件使用HTML5 history API。

#2


7  

You have to use HTML5's pushState() method to change browser history.

您必须使用HTML5的pushState()方法来更改浏览器历史。

window.history.pushState(data, "Title", "/new-url");

Doc says:

医生说:

pushState() takes three parameters: a state object, a title (which is currently ignored), and (optionally) a URL.

pushState()接受三个参数:状态对象、标题(当前被忽略)和URL(可选)。

The last argument is the new URL. For security reasons you can only change the path of the URL, not the domain itself. The second argument is a description of the new state. And the first argument is some data that you might want to store along with the state.

最后一个参数是新的URL。出于安全原因,您只能更改URL的路径,而不能更改域本身。第二个参数是对新状态的描述。第一个参数是一些你可能想随状态一起存储的数据。


推荐阅读
  • 使用eclipse创建一个Java项目的步骤
    本文介绍了使用eclipse创建一个Java项目的步骤,包括启动eclipse、选择New Project命令、在对话框中输入项目名称等。同时还介绍了Java Settings对话框中的一些选项,以及如何修改Java程序的输出目录。 ... [详细]
  • Vue基础一、什么是Vue1.1概念Vue(读音vjuː,类似于view)是一套用于构建用户界面的渐进式JavaScript框架,与其它大型框架不 ... [详细]
  • 初探PLC 的ST 语言转换成C++ 的方法
    自动控制软件绕不开ST(StructureText)语言。它是IEC61131-3标准中唯一的一个高级语言。目前,大多数PLC产品支持ST ... [详细]
  • JSCoverage-->JavaScript测试覆盖率检测工具(转),Go语言社区,Golang程序员人脉社 ... [详细]
  • 凡客诚品官方网站的前端改进建议
    打开http:www.vancl.com发现采用的Asp.net,这点我感到很欣慰,毕竟国内采用.net技术体系的优秀网站少之又少。好奇之余右键-查看源 ... [详细]
  • Nginx使用(server参数配置)
    本文介绍了Nginx的使用,重点讲解了server参数配置,包括端口号、主机名、根目录等内容。同时,还介绍了Nginx的反向代理功能。 ... [详细]
  • 本文介绍了Java工具类库Hutool,该工具包封装了对文件、流、加密解密、转码、正则、线程、XML等JDK方法的封装,并提供了各种Util工具类。同时,还介绍了Hutool的组件,包括动态代理、布隆过滤、缓存、定时任务等功能。该工具包可以简化Java代码,提高开发效率。 ... [详细]
  • Linux如何安装Mongodb的详细步骤和注意事项
    本文介绍了Linux如何安装Mongodb的详细步骤和注意事项,同时介绍了Mongodb的特点和优势。Mongodb是一个开源的数据库,适用于各种规模的企业和各类应用程序。它具有灵活的数据模式和高性能的数据读写操作,能够提高企业的敏捷性和可扩展性。文章还提供了Mongodb的下载安装包地址。 ... [详细]
  • 本文介绍了前端人员必须知道的三个问题,即前端都做哪些事、前端都需要哪些技术,以及前端的发展阶段。初级阶段包括HTML、CSS、JavaScript和jQuery的基础知识。进阶阶段涵盖了面向对象编程、响应式设计、Ajax、HTML5等新兴技术。高级阶段包括架构基础、模块化开发、预编译和前沿规范等内容。此外,还介绍了一些后端服务,如Node.js。 ... [详细]
  • 一次上线事故,30岁+的程序员踩坑经验之谈
    本文主要介绍了一位30岁+的程序员在一次上线事故中踩坑的经验之谈。文章提到了在双十一活动期间,作为一个在线医疗项目,他们进行了优惠折扣活动的升级改造。然而,在上线前的最后一天,由于大量数据请求,导致部分接口出现问题。作者通过部署两台opentsdb来解决问题,但读数据的opentsdb仍然经常假死。作者只能查询最近24小时的数据。这次事故给他带来了很多教训和经验。 ... [详细]
  • 本文介绍了2015年九月八日的js学习总结及相关知识点,包括参考书《javaScript Dom编程的艺术》、js简史、Dom、DHTML、解释型程序设计和编译型程序设计等内容。同时还提到了最佳实践是将标签放到HTML文档的最后,并且对语句和注释的使用进行了说明。 ... [详细]
  • ①页面初始化----------收到客户端的请求,产生相应页面的Page对象,通过Page_Init事件进行page对象及其控件的初始化.②加载视图状态-------ViewSta ... [详细]
  • JavaScript与DOM(上)——也适用于新手 – 深入理解JavaScript系列 23
    本文是《JavaScript深度解析》系列文章第23篇(共51篇)文档对象模 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 本文总结了在编写JS代码时,不同浏览器间的兼容性差异,并提供了相应的解决方法。其中包括阻止默认事件的代码示例和猎取兄弟节点的函数。这些方法可以帮助开发者在不同浏览器上实现一致的功能。 ... [详细]
author-avatar
杨艳奎_718
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有