Skip to Content
JAVASCRIPT網頁應用程式設計
book

JAVASCRIPT網頁應用程式設計

by Alex MacCaw
January 2013
Intermediate to advanced
332 pages
5h 23m
Chinese
GoTop Information, Inc.
Content preview from JAVASCRIPT網頁應用程式設計
48
|
第三章
利用 Ajax 載入資料
相信當你聽到「背景發出請求」時,第一個浮現在腦海中的做法,應該就是利用 Ajax
來載入遠端資料。原因很簡單:這是一種經過許多程式設計師反覆測試驗證後確認可行
的做法,而且所有目前主流的瀏覽器都支援這種做法。但並不是說 Ajax 就沒有任何缺
點—由於它過去是一項未經標準化的技術,導致今日我們所見到的 Ajax API 並不一致;
此外,如果需要載入其他網域的網站資料,會因為瀏覽器的安全性限制,造成一些較難
處理的狀況。
如果想先學習一些有關 Ajax
XMLHttpRequest
類別的基礎概念,建議可以拜讀
Mozilla Developer 網站上的一篇文章「Getting Started」(
https://developer.mozilla.org/
en/Ajax/Getting_Started
)。由於大多數人應該都會採用一些已經把 Ajax API 抽象化的
函式庫(像是 jQuery),來處理跨瀏覽器的相容性問題。因此,本書不會再特別介紹
XMLHttpRequest
類別,會直接說明 jQuery API
jQuery Ajax API,除了提供較底層的函式
jQuery.ajax()
以外,還會在它之上提供一
層更抽象化的程式介面,讓需要撰寫的程式碼變得更少。呼叫
jQuery.ajax()
函式時,
需要傳入一堆請求相關的參數設定,像是文件類型(content type)、回叫函式…等等。
呼叫這個函式之後,程式就會在背景發出非同步的請求。
url ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

初めてのJavaScript 第3版 ―ES2015以降の最新ウェブ開発

初めてのJavaScript 第3版 ―ES2015以降の最新ウェブ開発

Ethan Brown, 武舎 広幸, 武舎 るみ
PHP编程:第4版

PHP编程:第4版

Kevin Tatroe, Peter MacIntyre
Strange Code

Strange Code

Ronald T. Kneusel
Perfecting Your Thinking Skills

Perfecting Your Thinking Skills

MIT Sloan Management Review

Publisher Resources

ISBN: 9789862766811