AJAX请求和常规浏览器请求之间的区别 [英] Difference between AJAX request and a regular browser request

查看:562
本文介绍了AJAX请求和常规浏览器请求之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AJAX请求和直接浏览器请求之间是否存在差异(就如何调用和加载网页而言)?

Is there a difference between an AJAX request and a direct browser request (in terms of how a web page is called and loaded)?

换句话说,我mean:是一个直接服务器端请求,以不同于客户端请求(由浏览器发起)的方式处理?

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)?

推荐答案

就服务器而言,AJAX请求与正常浏览器请求相同,而不是可能略有不同的HTTP标头。例如chrome发送:

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

我不确定该标头是否标准化,或者它是否在每个浏览器中都不同,甚至在每个浏览器中都包含

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.

编辑:我接回来了,那个标题是由jQuery(可能还有其他JS库)发送的,而不是浏览器发送的证明:

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();

发送:

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

这使我得出结论默认绝对没有区别。

which leads me to the conclusion that by default there is absolutely no difference.

这篇关于AJAX请求和常规浏览器请求之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆