問題描述
AJAX 請求和直接瀏覽器請求之間有區(qū)別嗎(就網(wǎng)頁的調(diào)用和加載方式而言)?
Is there a difference between an AJAX request and a direct browser request (in terms of how a web page is called and loaded)?
換句話說,我的意思是:直接服務(wù)器端請求的處理方式是否不同于客戶端請求(由瀏覽器發(fā)起)?
In other words, I mean: is a direct server-side request handled in any way differently than a client-side request (initiated by the browser)?
推薦答案
就服務(wù)器而言,AJAX 請求與正常"瀏覽器請求相同,除了可能略有不同的 HTTP 標(biāo)頭.例如chrome 發(fā)送:
An AJAX request is identical to a "normal" browser request as far as the server is concerned other than potentially slightly different HTTP headers. e.g. chrome sends:
X-Requested-With:XMLHttpRequest
我不確定該標(biāo)頭是否標(biāo)準(zhǔn)化,或者它是否在每個瀏覽器中都不同,甚至是否在每個瀏覽器中都包含 .
I'm not sure if that header is standardized or not, or if it's different in every browser or even included at all in every browser.
我收回這一點,該標(biāo)頭是由 jQuery(可能還有其他 JS 庫)發(fā)送的,而不是由瀏覽器發(fā)送的,如下所示:
edit: I take that back, that header is sent by jQuery (and likely other JS libraries), not the browser as is evidenced by:
var xhr = new XMLHttpRequest();
xhr.open('GET', '/');
xhr.send();
發(fā)送:
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Cookie: ....
Host:stackoverflow.com
If-Modified-Since:Sat, 31 Dec 2011 01:57:24 GMT
Referer:http://stackoverflow.com/questions/8685750/how-does-an-ajax-request-differ-from-a-normal-browser-request/8685758
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.12 Safari/535.11
這使我得出結(jié)論,默認(rèn)情況下絕對沒有區(qū)別.
which leads me to the conclusion that by default there is absolutely no difference.
這篇關(guān)于AJAX 請求和普通瀏覽器請求的區(qū)別的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!