如何检测,如果一个请求是阿贾克斯还是正常在服务器端求是、服务器端、正常、阿贾克斯

2023-09-10 17:20:44 作者:心如泡沫ˇ一碰就碎

使用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"}
});
 
精彩推荐
图片推荐