Home >Web Front-end >JS Tutorial >How to remove X-Requested-With_jquery from jQuery's ajax request

How to remove X-Requested-With_jquery from jQuery's ajax request

WBOY
WBOYOriginal
2016-05-16 17:09:381441browse

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

Copy code The code is as follows:

$.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
Copy code The code is as follows:

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