Receiving a XHR 404 error when trying to upload an mp3 file, even though the directory clearly

I am currently working on a project where users will be able to upload an mp3 file of their choice through JavaScript and AJAX. Here's the code snippet I have so far:

// Creating the file upload button
var uploadBtn = document.createElement("input");
uploadBtn.innerHTML = "Browse...";
uploadBtn.id = "fileToUpload";
uploadBtn.type = "file";

// Creating a submit button
var submitButton = document.createElement("button");
submitButton.innerHTML = "Submit";
submitButton.id = "submitButton";

Once the user selects their file and clicks the submit button (where mp3File and formdata are global variables set elsewhere), this block of code is executed:

mp3File = document.getElementById("fileToUpload").files[0];
formdata = new FormData();
formdata.append("mp3File", mp3File);
var req = new XMLHttpRequest();
req.open("POST", 'mp3_uploads/', true);
req.send(formdata);

However, I keep encountering the following error:

XHR POST [path to my website here]/mp3_uploads/ ---> HTTP/1.1 - 404 - Not Found

Despite having the directory set up on my server, I still receive this error message. While I do have a working solution using a separate HTML form that references a PHP file for mp3 file uploads, I would prefer sticking with the JavaScript / AJAX method if possible.

Any assistance on resolving this issue would be greatly appreciated.

Answer №1

Even though the directory is present, it doesn't consist of a script. Moreover, a directory is incapable of processing a POST request, resulting in a 404 error.

To resolve this issue, consider developing a PHP script (or any other server-side language) that can manage the file and store it in the specified directory.

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

The JavaScript function is not functioning properly, whereas another function is working as intended

I have created a HTML form with 2 buttons and a table. Each row in the table consists of a checkbox and 2 text fields. The buttons allow users to add and remove rows from the table. The remove button only applies to rows where their checkbox is checked. T ...

Capture all URLs containing [...slug] and generate static props only for valid addresses in Next.js

I am utilizing dynamic routes with the fallback:true option to ensure newly created pages are accepted. First, I check if the parameters are true, then I create related props and display the component with those props. In the console, I can observe that Ne ...

The function Getter is expected, but an error has occurred with "getters.doubleCounter" returning a value of 20 in VUEX

Currently, I am diving into the world of Vuex and encountering some challenges along the way. In my attempt to create a getter on my vuex instance, I am facing an error when trying to display data from one of my components: The getter should be a functi ...

Progress bar for AJAX file loading for Flash player

Looking to create a progress bar using AJAX for a flash file. Check out this demo here: I tried to analyze their page, but the JavaScript is encrypted and I'm not very skilled in JS. Any suggestions? Thank you! ...

Rendering v-html in VueJS requires a delayed binding value that can only be triggered by clicking inside and outside of a textarea control

I'm currently experiencing an issue with a textarea that is bound to a v-model with a specific value. The problem arises when the content of the textarea is changed via JavaScript - the displayed value, represented by {{{value}}}, doesn't update ...

Using space as a separator for thousands when formatting integers

In an attempt to change the appearance of 1000 to resemble 10 000, I found numerous examples online on how to add a separator such as a comma or some StringLocal. However, I am looking for a way to use a space instead. Can anyone advise me on which locale ...

Transferring multiple data between PHP and JavaScript

Here is the code I am using for the on change event: <script> $('.BIR').change(function() { var id = $(this).val(); //get the current value's option $.ajax({ type:'POST', dataType: "json", ...

Implementing event handling with .On() in Jquery following .Off()

I need assistance with my responsive navigation bar. I am having trouble with the jQuery code to disable hover events if the width is less than or equal to 768px and enable it for desktop screens. $(window).on('load resize', function (e) { v ...

Is there a way to retrieve a numerical value from within two specific elements when web scraping?

I am new to web scraping and looking to extract the numbers located between the strong tags. Currently, I am using Python 3.8 along with BeautifulSoup for this task. <li class="price-current"> <span class="price-current-label"> </s ...

Issue arising when attempting to dynamically load an image using Vue and Webpack

I recently set up an application using the Vue CLI, and within one of my components, I have included the following code snippet: <template> <div v-loading="loading"> <el-carousel :interval="4000" type="card" height="350px"> & ...

Issues arise with AJAX requests while using gunicorn after logging out from the server

Over the weekend, I successfully deployed my first Django application on a VPS server. Setting up PostgreSQL, PostGIS, virtualenv, and other necessary components took some time, but I finally got the application up and running. While everything worked fin ...

Drop-down menu for every individual cell within the tabular data

I'm working with a large HTML table that looks like this: <table> <tr> <td>value1</td> <td>value2</td> </tr> <tr> <td>value3</td> <td>value4 ...

Empty MongoDB array persists even after POST request

After performing a POST request in Insomnia, my "games" array remains empty. What am I missing? UPDATE: New error after array.push({}) "errorValidationError: games.0.gameID: Path gameID is required., games.0.isGameActivated: Path isGameActivated is requi ...

Using JavaScript to organize and reformat JSON data into grouped structures

In my dataset, I am unable to make any formatting adjustments or modifications. //input json data [ { "Breaks":[ {"points":12,"points_total":12,"average":8.0,"faults":[]}, {"points":17,"points_total":29,"average ...

Node server quickly sends a response to an asynchronous client request

Apologies for my lack of writing skills when I first wake up, let me make some revisions. I am utilizing expressjs with passportjs (local strategy) to handle my server and connect-busboy for file uploads. I believe passport will not have a role in this pr ...

Unable to reach a variable within the class itself

I'm facing an issue with my MobX store. In my Store class, when I try to access this.user.permits.db, I get an error stating that this.user is undefined. I am confused as to why I can't access the @observable user. src/ui/store/store.js file: ...

Disabling the intellisense feature for locale suggestions in Monaco is recommended

Switch the keyboard language to a different one (in this case Japanese using alt + shift), and when typing in Monaco editor, an intellisense menu appears with options to remove and search. Monaco Editor Version: V0.33.0 https://i.stack.imgur.com/SIyeV.pn ...

What is the best way to extract multiple values from a JavaScript variable and transfer them to Node.js?

Script JavaScript script snippet embedded at the bottom of an HTML file: var savedValues = [] var currentId = document.getElementById("fridgeFreezer").value function handleChange() { // Logic to handle user input changes: var temp = document.ge ...

Obtain individual information from XML

After fetching data from the server using ajax, I am looking to retrieve only a specific part of the data which is the name. How can I modify my code to achieve this? const url = 'https://jsonplaceholder.typicode.com/users' const xhr = new XMLH ...

Ensuring model accuracy in Asp.Net Core prior to initiating an Ajax request via JavaScript

Here is a snippet of code that I am currently using, which is triggered on a button click event. The question I have is regarding the validation of my viewmodel object before sending an ajax call. I can see model errors in JavaScript, but I'm unsure o ...