SO如何动态获取其标签?

时间:2013-01-29 23:29:26

标签: javascript jquery ajax stack-overflow

当您提出问题时,stackoverflow如何在下面的标记输入上加载其可用标记?他们在页面加载时填充可用的标签,还是按用户输入或用户按键发出请求?我打算在我的应用程序中以相同的方式实现,但我不知道如何实现这个目标。

1 个答案:

答案 0 :(得分:1)

他们肯定不会在页面加载时加载所有可用的标记,因为有太多。我在Firefox的Web控制台下运行了一个快速测试,看起来他们使用AJAX做了一个JSON请求。一个例子是:

https://stackoverflow.com/filter/tags?q=visual&newstyle=true&_=1359502308905

回应结果:

[{"Name":"c#","Synonyms":"visual-c#","Count":409187,"Excerpt":"C# is a multi-paradigm programming language encompassing strong typing, imperative, declarative, functional, generic, object-oriented (class-based), and component-oriented programming disciplines. It was developed by Microsoft for use with their .NET framework and later approved as a standard by Ecma (ECMA-334) and ISO (ISO/IEC 23270:2006). It is now also available on different platforms (Android, Linux, iOS) via the MONO project."},{"Name":"visual-studio-2010","Synonyms":"visual-studio-2010-rtm","Count":30434,"Excerpt":"Visual Studio is an integrated development environment (IDE) from Microsoft."},{"Name":"visual-studio","Synonyms":"visualstudio","Count":25157,"Excerpt":"Visual Studio is an integrated development environment (IDE) from Microsoft. It supports many different programming languages."},{"Name":"visual-studio-2008","Synonyms":"visualstudio2008","Count":13539,"Excerpt":"This tag refers to the Visual Studio line of software development products from Microsoft, the 2008 version."},{"Name":"visual-c++","Synonyms":"visualc++","Count":12298,"Excerpt":"Microsoft Visual C++ is a C and C++ compiler for Windows. The most recent version of the compiler is Visual C++ 2012, which is available in both commercial editions and in a free Express Edition.\r\n\r\nThe compiler supports the following languages:\r\n\r\n\r\nC: Only the C90 standard is supported; there is very limited C99 support\r\nC++: Also includes support for several major C++11 features as of Visual Studio 2010\r\nC++/CLI and .NET Managed Extensions for C++"},{"Name":"vba","Synonyms":"visual-basic-applications","Count":12195,"Excerpt":"Visual Basic for Applications (VBA) is an event-driven programming language which was first introduced by Microsoft in 1993 to give Excel 5.0 a more robust object-oriented language for writing macros and automating the use of Excel.  It is now used for the entire Office suite. If your question is specifically about programming Excel, Access, Word or Outlook, use the appropriate tag: excel-vba, access-vba, word-vba or outlook-vba."}]

它们似乎也有点滞后,因此它们不会立即触发过多的HTTP请求。在完成请求之前,您必须停止输入一两秒钟。