Remove X-Requested-With from the jQuery Ajax request

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

X-Requested-With is used to determine the Is it right? Ajax request

But sometimes we will need to remove X-Requested-With.

The code for a JS

$.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, judge Ajax request method java code

if (request.getHeader("x-requested-with") != null
    && request.getHeader("x-requested-with").equalsIgnoreCase("XMLHttpRequest")) {
    //The asynchronous request
}else{ 
     
}


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Zero at March 04, 2014 - 4:58 AM