ajax应用_AJAX的应用
ajax應(yīng)用
AJAX has several benefits that can be utilized inside a web application. In this article, we'll explore some advantages of AJAX and see some of its applications.
AJAX具有可在Web應(yīng)用程序內(nèi)部使用的多個(gè)優(yōu)點(diǎn)。 在本文中,我們將探討AJAX的一些優(yōu)勢,并了解其一些應(yīng)用 。
編寫回調(diào) (Writing Callbacks)
Recall that a simple callback function is just one function calling another one by taking the latter as a parameter. We can use AJAX to make a callback in many applications without waiting for the page to respond with the data. Now, this has an advantage when it comes to building an application that runs fast and smoothly thereby providing great user experience. The network speeds up and performance becomes better because the network utilization is considerably reduced. Similarly, if a website has a restricted bandwidth, it considerably boosts up. This is a great exploitation of the fact that many times writing AJAX requests we only need a small amount of data for our application. It doesn't make sense to have a large response time for minimal data. The response time, network load and speed should be in accordance with the kind and amount of data we're taking in.
回想一下,簡單的回調(diào)函數(shù)只是一個(gè)將另一個(gè)作為參數(shù)調(diào)用的函數(shù)。 我們可以使用AJAX在許多應(yīng)用程序中進(jìn)行回調(diào),而無需等待頁面響應(yīng)數(shù)據(jù)。 現(xiàn)在,這對(duì)于構(gòu)建快速且平穩(wěn)運(yùn)行的應(yīng)用程序具有優(yōu)勢,從而提供了出色的用戶體驗(yàn)。 由于網(wǎng)絡(luò)利用率大大降低,因此可以加快網(wǎng)絡(luò)速度并提高性能。 同樣,如果網(wǎng)站的帶寬受到限制,則可以大大提高網(wǎng)站的帶寬。 這是對(duì)以下事實(shí)的一種很好的利用:多次編寫AJAX請(qǐng)求,我們的應(yīng)用程序只需要少量數(shù)據(jù)。 響應(yīng)時(shí)間長,數(shù)據(jù)量少是沒有意義的。 響應(yīng)時(shí)間,網(wǎng)絡(luò)負(fù)載和速度應(yīng)與我們要接收的數(shù)據(jù)的種類和數(shù)量一致。
進(jìn)行異步調(diào)用 (Making Asynchronous Calls)
The asynchronous behavior of an application is the magic behind single-page applications. These days modern applications have a single page with multiple functions that are undisturbed when the process is fetching data from a server is going on the background. These asynchronous calls can be made with Ajax to a backend, API or a server. As a user, we never have to wait for that data to come back for seeing other pages on the website or seeing some content.
應(yīng)用程序的異步行為是單頁應(yīng)用程序背后的魔力。 如今,現(xiàn)代應(yīng)用程序只有一個(gè)頁面,其中包含多個(gè)功能,而這些功能在后臺(tái)從服務(wù)器獲取數(shù)據(jù)的過程中不受干擾。 可以使用Ajax對(duì)后端,API或服務(wù)器進(jìn)行這些異步調(diào)用。 作為用戶,我們無需等待數(shù)據(jù)返回就可以看到網(wǎng)站上的其他頁面或看到某些內(nèi)容。
Alright so AJAX is used to write callbacks and making async calls, but where are these benefits utilized?
好的,所以AJAX用于編寫回調(diào)和進(jìn)行異步調(diào)用,但是這些好處在哪里得到利用?
1)登錄表格 (1) Login forms)
Working with AJAX in login forms is a great way to understand it's an advantage. We create a simple login form and attach an event listener to our submit event. When this event is triggered, we make an AJAX call to our database and check for valid user credentials. All of this without the slightest need to steer away from the current page or reloading the pageA popular site like Digg has a login system that works this way.
以登錄表單使用AJAX是了解它的一個(gè)好方法。 我們創(chuàng)建一個(gè)簡單的登錄表單,并將事件偵聽器附加到我們的Submit事件。 觸發(fā)此事件后,我們將對(duì)數(shù)據(jù)庫進(jìn)行AJAX調(diào)用,并檢查有效的用戶憑據(jù)。 所有這些都完全不需要轉(zhuǎn)向當(dāng)前頁面或重新加載頁面。像Digg這樣的受歡迎的網(wǎng)站都具有以這種方式工作的登錄系統(tǒng)。
2)自動(dòng)完成 (2) Autocomplete)
Google was one of the first major companies to start using AJAX. When google's search engine tool came out everyone was talking about it. You must have not noticed that the autocomplete feature inside their engine was dynamic even back then, courtesy of AJAX. When typing into the Google search bar, it starts to use AJAX to get common results from the database on each keystroke. Even now you can use AJAX to add auto-complete features on your web application easily. This is also implemented in many UI Libraries which give us the autocomplete feature using an inbuilt plugin but inside it's simple AJAX callback working on the autocomplete feature.
Google是最早使用AJAX的主要公司之一。 當(dāng)Google的搜索引擎工具問世時(shí),所有人都在談?wù)撍?您可能還沒有注意到,即使在那時(shí),其引擎內(nèi)的自動(dòng)完成功能還是動(dòng)態(tài)的,這要?dú)w功于AJAX。 在Google搜索欄中鍵入內(nèi)容時(shí),它將開始使用AJAX在每次擊鍵時(shí)從數(shù)據(jù)庫中獲取常見結(jié)果。 即使現(xiàn)在,您也可以使用AJAX在Web應(yīng)用程序上輕松添加自動(dòng)完成功能。 許多UI庫中也實(shí)現(xiàn)了此功能,這些庫使用內(nèi)置插件為我們提供了自動(dòng)完成功能,但是在內(nèi)部,簡單的AJAX回調(diào)在其中使用了自動(dòng)完成功能。
3)動(dòng)態(tài)更新內(nèi)容 (3) Dynamically updating content)
It shouldn't be a surprise that popular social media platforms established their dominance on the web by showing the user's feed, comments, posts, etc dynamically without the need to refresh the page. The AJAX engine would fetch data in real-time and show it to the user. This is how the page would update content dynamically and offers a great user experience.
流行的社交媒體平臺(tái)無需刷新頁面即可動(dòng)態(tài)顯示用戶的供稿,評(píng)論,帖子等,從而在網(wǎng)絡(luò)上占據(jù)統(tǒng)治地位,這不足為奇。 AJAX引擎將實(shí)時(shí)獲取數(shù)據(jù)并將其顯示給用戶。 該頁面將以這種方式動(dòng)態(tài)更新內(nèi)容并提供出色的用戶體驗(yàn)。
4)聊天應(yīng)用 (4) Chatting applications)
Long ago, back when instant messaging had just come out and had started gaining immense popularity, most online chat rooms and chat apps were using AJAX requests for the complete functioning of their chatting applications.
很久以前,當(dāng)即時(shí)消息傳遞剛剛開始并開始受到極大歡迎時(shí),大多數(shù)在線聊天室和聊天應(yīng)用程序都使用AJAX請(qǐng)求來實(shí)現(xiàn)其聊天應(yīng)用程序的完整功能。
5)小部件和添加 (5) Widgets and adds)
Widgets were super popular back then just as much as ads are these days. You must have noticed a lot of times adds on a website changes after some time and all of this happens while you have been on the same page for the last 15 minutes doing possibly nothing but read out some wiki information that you need. You never clicked anywhere, never reloaded the page, the network speed was fantabulous. In such a situation if the page just out of nowhere grabs some data and updates it, while you're in awe wondering wasn't there an advertisement of mind valley here before? Now there's one for Mitashi. All of this because of AJAX callbacks and asynchronous AJAX requests.
窗口小部件在當(dāng)時(shí)非常流行,就像現(xiàn)在的廣告一樣。 您一定已經(jīng)注意到,一段時(shí)間后,網(wǎng)站上的很多次更改都發(fā)生了,而所有這一切都是在您過去15分鐘一直在同一頁面上時(shí)發(fā)生的,除了讀出所需的一些Wiki信息外,可能什么也沒有做。 您從來沒有單擊過任何地方,也從未重新加載過頁面,網(wǎng)絡(luò)速度異常驚人。 在這種情況下,如果頁面無處不在獲取一些數(shù)據(jù)并對(duì)其進(jìn)行更新,而您卻對(duì)此感到敬畏,那么您是否想知道這里是否曾有過廣告宣傳? 現(xiàn)在,三菱有一個(gè)。 所有這些都是由于AJAX回調(diào)和異步AJAX請(qǐng)求。
Reference: How AJAX Works: 10 Practical Uses For AJAX
參考: AJAX的工作原理:AJAX的10種實(shí)際用途
翻譯自: https://www.includehelp.com/ajax/applications.aspx
ajax應(yīng)用
總結(jié)
以上是生活随笔為你收集整理的ajax应用_AJAX的应用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mkdir 函数_PHP mkdir()
- 下一篇: win7变成xp风格了怎么改回_XP退役