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
- $(document).on('click', '.ordering_btn', function(){
- var item_id = $(this).data('value');
- var hotel_id = "<?php echo $hotel_id; ?>";
-
- $.ajax({
- type: 'GET',
-
- url: 'add_to_cart.php?item_id='+item_id+'&hotel_id='+hotel_id+'',
-
- contentType: 'text/plain',
-
- xhrFields: {
- withCredentials: false
- },
-
- headers: {
- "Access-Control-Allow-Headers": "X-Requested-With",
- "X-Requested-With": "XMLHttpRequest"
- },
-
- success: function(data) {
- $('#cart_msg').css('display', 'none');
- $('#cart_item').html(data);
- console.log(data);
- },
-
- error: function() {
- }
- });
- });