韓鑫 高佳華
摘 要: 在異域數(shù)據(jù)集成的Web應(yīng)用中,同源策略使AJAX跨域訪問受到了限制。闡述了避開同源策略的主要方案JSONP、Websocket、CORS等跨域方式的原理,進(jìn)而提出了基于CSS的最快最佳方案-CSST,最后介紹了該方法的實(shí)現(xiàn)原理和優(yōu)勢(shì)。實(shí)踐表明,該方法更有效地解決了AJAX跨域訪問和展現(xiàn)數(shù)據(jù)的問題。
關(guān)鍵詞: 跨域; AJAX; CSST; 同源策略
中圖分類號(hào):TP311 文獻(xiàn)標(biāo)志碼:A 文章編號(hào):1006-8228(2017)09-19-02
Abstract: In the Web applications with heterogeneous data integration, homology policies make AJAX cross-domain access restricted. The cross-domain access principles of JSONP, Websocket, CORS and so on are discussed, then, CSST the fastest and best solution based on CSS is proposed, and the principle and advantage of CSST are introduced. The practice shows that this method is more effective to solve the problems of AJAX cross-domain access and show the data.
Key words: cross-domain; AJAX; CSST; homology policy
0 引言
“同源策略”是瀏覽器安全的基石,所謂同源,即協(xié)議、域名、端口相同[1-3]。為了保證用戶信息的安全,防止惡意的網(wǎng)站竊取數(shù)據(jù),“同源策略”是必需的。然而,如果非同源,瀏覽器緩存數(shù)據(jù)無法讀取、DOM無法獲得、AJAX請(qǐng)求無效。實(shí)際開發(fā)中,為了實(shí)現(xiàn)資源在不同域之間的共享,常采用JSOPN、Websocket、CORS等跨域方案。
1 JSONP
JSONP是服務(wù)器與客戶端跨源通信的常用方法。最大特點(diǎn)就是簡(jiǎn)單適用,老式瀏覽器全部支持,服務(wù)器改造非常小?;舅枷胧?,網(wǎng)頁通過添加一個(gè)
客服熱線:400-656-5456??客服專線:010-56265043??電子郵箱:longyuankf@126.com
電信與信息服務(wù)業(yè)務(wù)經(jīng)營(yíng)許可證:京icp證060024號(hào)
Dragonsource.com Inc. All Rights Reserved