X-Requested-With is often used to determine whether it is an ajax request
But sometimes we need to delete X-Requested-With
Here is a way to introduce js code
$.ajax({
url: 'http://www. zhangruifeng.com',
beforeSend: function( xhr ) {
xhr.setRequestHeader('X-Requested-With', {toString: function(){ return ''; }});
},
success: function( data ) {
if (console && console.log){
console.log( 'Got data without the X-Requested-With header' );
}
}
});
Attached, the java code for judging ajax requests
if (request.getHeader("x-requested-with") != null
&& request.getHeader("x-requested-with").equalsIgnoreCase(" XMLHttpRequest")) {
//Asynchronous request
}else{
}
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn