The presence of the If-Modified-Since header causes the CORS OPTIONS request to experience failure

When using a custom header (If-Modified-Since) in the code below, it causes ajax to fail with a status of HTTP/1.1 405 Not Allowed for the OPTIONS preflight request. However, if the header is removed, the request works as expected (I am unsure if OPTIONS is not sent at all or if developer consoles just do not display it). Why does this happen? (Similar situation occurs with jquery hosted on googleapis).

http = new XMLHttpRequest();
http.open('GET', 'http://code.jquery.com/jquery-2.1.4.min.js');
http.setRequestHeader('If-Modified-Since', 'Sat, 29 Oct 1994 19:43:31 GMT')
http.send();

Furthermore, is there a method to include this header in the xhr request to the jquery cdn in order to receive a 304 response status?

Answer №1

It appears that the Web server is rejecting the use of the OPTIONS method. To verify this, look for an Allow header in the response (as per the HTTP specification), and see what methods are listed. If the Allow header does not include OPTION—for example, if it only lists GET, HEAD, PUT, then any OPTIONS requests will fail. Therefore, if your operation relies on using OPTIONS, it may not be compatible with this server.

According to CORS specifications, sending the If-Modified-Since header (or any other headers except Accept, Accept-Language, Content-Language, or specific Content-Type cases) triggers a preflight request, which necessitates using the OPTIONS method. However, it's important to note that not all Web servers are required to support the OPTIONS method, as mandated by CORS or any other standards. In cases where a server does not support OPTIONS, you can expect the type of response you're currently experiencing.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieving a column from a table and converting it into an array for utilization in a context processor on

I need to extract column data from a DB table using a Django context processor. This specific table column contains various versions of the primary data, so I want to gather all versions and pass them as context to an HTML page. The existing context proces ...

One-way communication between two clients using Socket.io

While working on a basic socket.io application using React and Express, I've encountered an issue where two clients are facing difficulties in sending data to each other. For instance: Player 1 connects to the server followed by Player 2. Player 1 ...

What is the best way to sequentially process data column by column and incorporate them into a three-dimensional model using three.js?

Currently, I am in the process of creating a 3D model using three.js that will accurately display the position and orientation of a vehicle using accelerometer and gyroscope data. I have collected all the necessary information in an xlsx file, including th ...

Issue with Blueprint query in SailsJS Version 1 - troubleshooting needed

I'm currently working on devising a blueprint query for a sailsjs v1 model. The model in question is the BlogPost model, which comprises 2 key "options". These options are known as target and Status. My goal is to have the query return only when the ...

Forget the function once it has been clicked

I'm looking for a solution to my resizing function issue. When I press a button, the function opens two columns outside of the window, but I want to reset this function when I click on another div. Is there a way to remove or clear the function from m ...

What is the best way to create a filter function that continues past the first false value?

Looking for a solution to successfully filter an array of objects by comparing it to another array through looping over its values. The issue arises when the filter function stops at the first false, preventing the full comparison. Any suggestions on how ...

Encountering a 500 internal server error after deploying due to utilizing getServerSideProps in Next.js

When trying to redeploy my website on Vercel, I added getServerSideProps to my index.js file. However, I encountered an error that I am not familiar with. The program works perfectly on localhost. This is the getServerSideProps code that I added: export a ...

Fancybox displaying error message: "Sorry, we are unable to load the requested content at this time. Please try again later."

Utilizing Fancybox for the purpose of displaying YouTube videos in a modal box. I am encountering an issue where I consistently receive the error message "The requested content cannot be loaded. Please try again later." The fact that the modal box is app ...

Error: Gulp task needs to have a function assigned to it at Gulp.set

Every time I attempt to execute gulp, I encounter the following error. Here is my gulpfile.js: var gulp = require('gulp'), connect = require('gulp-connect-php'), gulpPhpunit = require('gulp-phpunit'); ...

Render the React component asynchronously, only after the data has been successfully fetched

I am looking to display a component only after the necessary data has been fetched. If I try to load the data instantly, the component gets rendered but no information is displayed. class App extends React.Component { //typical construct fetchGameD ...

Refreshing Child's Activities

In my scenario, I am displaying data in a child action and utilizing buttons to modify the displayed information. Here is an example of how I am achieving this: Index.cshtml <head> <script type="text/javascript"> $("#RefreshView").on ...

single-spa: revolutionizing console.log for each microfrontEnd

Imagine having multiple single-spa react microfrontend apps in your project, such as Cart and Products The goal is to modify console.log, console.error, etc. so that they include a prefix indicating the corresponding microfrontend app: console.log call ...

What is behind the peculiar reaction when checkboxes are used in React?

In this demo, what is causing the button to disable only after both checkboxes have been checked? Is the button not initially displayed as disabled due to the way state behaves in react? The example consists of two checkboxes: I have read and agree to te ...

Using Jquery & HTML5 for Seamless Transition between Portrait and Landscape Modes

I am working on making my HTML page more user-friendly for tablets. One issue I'm facing is that when the tablet's orientation changes, the menu doesn't hide correctly if the width is less than the height. Here is the code snippet I have so ...

Can you provide a list of factors that influence coverage? Additionally, is there a specific algorithm available for calculating

As part of my Angular project, I am currently focusing on writing unit test cases using the Jasmine Framework and Karma. To ensure thorough testing coverage, I am utilizing Coverage-html (Istanbul). When it comes to coverage, there are several important t ...

Problem with Marionette AppRouter compatibility when used with Browserify

app.js module.exports = function () { if (!window.__medicineManager) { var Backbone = require('backbone'); var Marionette = require('backbone.marionette'); var MedicineManager = new Marionette.Application(); Medicin ...

"Uncovering a memory leakage issue within a recursive polling function in JavaScript

Current issue in need of resolution: My team and I are currently working on a large application that was initially released around two years ago. We are in the process of adding a new "always-on" status screen to the application, which will be the default ...

Fast search using two dropdown menus

Looking to implement a search functionality with two drop down boxes using ajax. Here's the code snippet: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script type="text/javascript"> $(do ...

VueJS - Input Image Display Issue Causing Browser Slowdown

I'm experiencing some issues with my VueJS component that includes a file input and displays an image afterwards. Strangely, this is causing my web browsers (both Firefox and Chromium) to freeze up and use massive amounts of CPU. I tried switching to ...

What is the process for switching directories and renaming a file when uploading in nodeJs?

I am currently using multer and fs to handle the upload of an image file. How can I modify the directory where uploaded files are stored? Currently, all files are saved in my "routes" folder instead of the "uploads" folder created by multer. Additionally, ...