How to pass custom header with ajax call in .Net MVC?

Forums ASP.NET MVCHow to pass custom header with ajax call in .Net MVC?
Staff asked 2 years ago

Answers (1)

Add Answer
Staff answered 2 years ago

Add the below code before your ajax call. This will set the header for all the ajax calls on your page. If you need to pass the same headers with multiple ajax calls then you can use this way.

$.ajaxSetup({
   beforeSend: function (xhr) {
      xhr.setRequestHeader('YOUR_HEADER_NAME', 'VALUE' );
      xhr.setRequestHeader('YOUR_HEADER_NAME_2', 'VALUE_2' );
   }
});

Subscribe

Select Categories