The preflight response received an unexpected HTTP status code 404 while processing an AJAX request in the browser

My ajax request is encountering a 404 error, here is the code:

$.ajax({
    type:'GET',
    url:'http://localhost:8000/auth/github',
    crossDomain:true,
    headers:{
        'Content-Type':'application/x-www-form-urlencoded',
        'Access-Control-Allow-Origin':'*'
    },
    success:function(data){debugger;}
});

The error is showing like this on chrome : see chrome error

And like this in firefox : see firefox error

I have installed a cors plugin in my browser and tried adjusting the headers, but the error persists in my web console.

Interestingly, accessing my route with Postman does not result in any issues, so I suspect the problem lies with my browser.

Does anyone have a solution to this issue?

I found a similar topic addressing the same error without a resolution yet: Ajax: Response for preflight has invalid HTTP status code 404

Thank you!

Answer №1

After some troubleshooting, I was able to solve the issue by including "accept:/" in my headers. I understand that this approach may not be suitable for real-world infrastructure, but it worked well for my school project. Hopefully, others facing a similar challenge can benefit from this workaround.

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

Error occurs when making Ajax request in Meteor but functions properly when testing on localhost

When attempting to retrieve data from my MySql database, I encountered an issue with 2 files: // client/book.js $(document).ready(function () { $("#btnJSonDB").bind("click", function () { var request = $.ajax({ ur ...

javascript how to retrieve the custom attribute value of an HTML style

I am dealing with an HTML element that has some inline styles as well as a custom CSS property. I am able to access every style attribute except for my custom style property. Here is the code I am working with: <img id="myimg" class="ImgClass" style=" ...

Track when a user clicks within a specific container in VueJS, excluding clicks on a specific child element

On my page, I have multiple choice question options that are structured like this: https://i.sstatic.net/oMH7t.png The following is the HTML code for the options section so far: <div v-for="(option, index) in optionsForFrontend"> <di ...

Tips for implementing the datatable method on a dynamically generated table

I have a scenario where I need to dynamically create a table by triggering a button click event. function populateTable() { $.ajax ({ url: 'php/GetData.php', type: 'POST', data: {id:25}, success: f ...

Generating multiple divs filled with content using JavaScript

Currently, I am diving into the world of JavaScript and aiming to develop something similar to the code snippet below using JavaScript. My goal is to easily adjust the number of images or divs that will be generated on the webpage. <div class="row"> ...

Error encountered due to an unhandled promise rejection of type

I am currently using async/await to execute a query to the database and receive the result. However, I encountered an error in the browser console that says: Unhandled promise rejection TypeError: "games is undefined" In my code, there are two function ...

In VuePress 1.x, the functionality of using the <Content> tag with pageKey is not functioning as expected

Throughout the development process, we implemented a component that would iterate through each index.md file within a folder based on the list this.$site.pages.path. However, after upgrading to version 1.0.0-alpha.39 in order to address some other issues w ...

create undirected lists using an array

I am trying to convert an array of sentences into unordered HTML lists, with each list item containing a word from the sentence. For example: [I play piano the can'] t <ul> <li id = number</li> <li>I</li> <li>play< ...

What is the best way to transfer a JS variable into a MySql database?

I have a JavaScript variable named count that I want to store in my MySQL database. let count = 0; countup.addEventListener("click", function() { count = count + 1; counter.innerText = count; let avgberechnung = count / 365; avg.innerText ...

The overlappingmarkerspidifier is throwing an error because it is unable to access the property '__e3_' of an undefined variable

I am attempting to implement the overlapping marker spidifier feature in my code. I followed the instructions provided in this link: functioning code of oms However, upon creating the OverlappingMarkerSpiderfier object, I encounter the error: Uncaught Typ ...

No matter the way I input the URL in the AJAX call, the response always comes back as successful

I ran into an issue with my ajax request. It was supposed to be a GET request that returned some data, but no matter how I configured the URL, it always gave a success response even when it didn't actually succeed. var id = 5; $.ajax({ type: ...

Peer dependency conflict detected: [email protected] is conflicting with node_modules/webpack. npm encountered an error while trying to

I recently cloned a repository from GitHub and proceeded to install npm packages using the npm install command. However, I encountered an error which is depicted in the image linked below: https://i.sstatic.net/1KnrA.jpg "devDependencies": { ...

Adding video files and subtitle files to our MongoDB database

// backend/server.ts import express, { Application, Request, Response } from 'express'; import mongoose from 'mongoose'; import cors from 'cors'; import dotenv from 'dotenv'; const multer = require('multer&apos ...

Tips for adjusting the margin of a print document in a printTask?

Is there a way to achieve a borderless print? Currently, my printed output has a border around it. I would like the image to start at the top left corner without any borders. I attempted to set a negative margin to the print-style box, but it resulted in ...

A Lilypond equivalent for Mathjax

Does anyone know of a tool that can convert Lilypond content into an image, similar to how Mathjax works? I think it would be great to create a music-focused Stack Exchange forum. It could offer valuable features like LaTeX on sites such as . ...

The value of an AngularJS service is not being reflected in the view

I have implemented the stateProvider in my code, and I am facing an issue with updating the breadcrumbs in the header when the state changes. Instead of creating embedded views for each state, I have a service that shares an array of breadcrumbs containing ...

Completing a form using ajax without navigating away from the sign up page

I am new to AJAX and researching how to submit a form using this technology. My current logic involves validating the form, making an ajax request, and handling different outcomes based on server-side errors or success messages. //validate form //if inva ...

Encountering a 404 Error on all routes except the home page when working with the Express Application Generator

While working on developing a day planner, I encountered an issue with the routes. I am consistently receiving a 404 error for any route other than the main Home page route (index or "/"). Below is the content of the app.js file: var express = require(&ap ...

Creating a default parameter for a JavaScript AJAX request function

Utilizing XML AJAX to retrieve URLs for streaming media playback upon button click. To display a startup Tamil channel list by default, default parameter value must be set to 'Tamil'. <button type="button" onclick="loadDoc('Tamil')" ...

Error message: 'firebase/app' does not export 'app' (imported as 'firebase') - Import attempt failed

Encountered a strange issue today. As I tried to import firebase, an error popped up: ./node_modules/firebaseui/dist/esm.js Attempted import error: 'app' is not exported from 'firebase/app' (imported as 'firebase'). The setup ...