X-Requested-With is not allowed by Access-Control-Allow-Headers

X-Requested-With is not allowed by Access-Control-Allow-Headers

I am developing one system. In that system there is one add item to cart functionality. In that functionality, I am using Jquery $.ajax used. But online server I have facing this error -

"XMLHttpRequest cannot load domain name/add_to_cart.php?item_id=3&hotel_id=2. Request header field X-Requested-With is not allowed by Access-Control-Allow-Headers."

Can any help me how to solve this error.

I am using this jquery code


  1. $(document).on('click', '.ordering_btn', function(){
  2.     var item_id = $(this).data('value');
  3.     var hotel_id = "<?php echo $hotel_id; ?>";

  4.     $.ajax({
  5.       type: 'GET',

  6.       url: 'add_to_cart.php?item_id='+item_id+'&hotel_id='+hotel_id+'',

  7.       contentType: 'text/plain',

  8.       xhrFields: {
  9.         withCredentials: false
  10.       },

  11.       headers: {
  12.         "Access-Control-Allow-Headers": "X-Requested-With",
  13.         "X-Requested-With": "XMLHttpRequest"        
  14.       },

  15.       success: function(data) {
  16.         $('#cart_msg').css('display', 'none');
  17.         $('#cart_item').html(data);
  18.         console.log(data);
  19.       },

  20.       error: function() {
  21.       }
  22.     });
  23. });