如何一个Ajax请求,从一个普通的浏览器要求有什么不同? [英] how does an Ajax request differ from a normal browser request?

查看:106
本文介绍了如何一个Ajax请求,从一个普通的浏览器要求有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家。这个问题一直缠着我了一段时间;

everybody. This question has been bugging me for a while;

是,而不是一个直接浏览器请求有如何的网页会被调用,通过Javascript的AJAX请求被称为加载的区别,?

(即做请求看起来与服务器端的不同,并在客户端/浏览器端的处理方式不同的答案?)

推荐答案

这是Ajax请求的一样的一个正常的浏览器至于服务器而言比可能略有不同的HTTP头的其他请求。例如镀铬发送:

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

我不知道如果这头是标准化的或者没有,或者如果它在每一个浏览器的不同在每一个浏览器,甚至包含的所有的。

编辑:我收回那句话,这头的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天全站免登陆