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{
}