区分之间的AJAX调用/浏览器请求 [英] Differentiating Between an AJAX Call / Browser Request

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

问题描述

是否有一个HTTP请求,让我到一个AJAX调用,并从给定的客户端直接浏览器请求区分的头什么?是用户代理字符串通常是相同​​的,不管?

Is there anything in the header of an HTTP request that would allow me to differentiate between an AJAX call and a direct browser request from a given client? Are the user agent strings usually the same regardless?

推荐答案

如果您使用的原型,jQuery的,Mootools的或YUI你应该找一个 X-要求,通过:XMLHtt prequest 头它会做的伎俩为您服务。它应该是可以插入任何的头部,你想用其他库。

If you use Prototype, jQuery, Mootools or YUI you should find a X-Requested-With:XMLHttpRequest header which will do the trick for you. It should be possible to insert whatever header you like with other libraries.

目前的最低水平,给予 XMLHtt prequest 或XMLHTTP对象,你可以设置与 setRequestHeader 方法,此头如下:

At the lowest level, given a XMLHttpRequest or XMLHTTP object, you can set this header with the setRequestHeader method as follows:

xmlHttpRequest.setRequestHeader('X-Requested-With', 'XMLHttpRequest');

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

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