如何检测,如果一个请求是阿贾克斯还是正常在服务器端 [英] how to detect if a request is ajax or normal on server side
本文介绍了如何检测,如果一个请求是阿贾克斯还是正常在服务器端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用jQuery使Ajax请求IM。它是可以检测,如果该请求是一个Ajax请求或在服务器端正常的请求?并jQuery的添加任何输入变量或标题,使这一切成为可能?
im using jquery to make ajax requests. is it possible to detect if the request is an ajax request or a normal request on the server side? does jquery add any input variables or headers to make this possible?
感谢
推荐答案
jQuery的秒时,它被称为AJAX头请求额外的头 X-要求 - 以
带 XMLHtt prequest
的价值。检查的要求这个头。
jQuery seconds an additional header on the request when it's ajax header called X-Requested-With
with a value of XMLHttpRequest
. Check for this header on the request.
另外,设置您想使用的任何标题 .ajaxSetup
是这样的:
Alternatively, set any header you want using .ajaxSetup
like this:
$.ajaxSetup({
headers: {"X-My-Header":"Bob"}
});
这篇关于如何检测,如果一个请求是阿贾克斯还是正常在服务器端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文