Question

I use Ajax.BeginForm.. It loads me partial view. This view have links. After view is loaded via ajax each link has href that ends with X-Requested-With=XMLHttpRequest. How can I disable automatic appending this parameter to my links?

Was it helpful?

Solution

This header is sent by jQuery everytime you perform an AJAX request. You could try disabling it by globally subscribing to the ajaxSend handler and overriding its value:

$(document).ajaxSend(function(event, jqXHR, ajaxOptions) {
    jqXHR.setRequestHeader('X-Requested-With', { 
        toString: function() { return ''; } 
    });
});

Notice that this will only set the value of the header to an empty string. It won't remove it from the request. A bug has been filed in jQuery asking to have the possibility to completely remove this request header and apparently it was rejected as not a bug.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top